Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define tables outside of functions, creating new table like this every
- -- time you hit a part would be waste of performance, better to store it
- -- the memory once
- local RemoveableCaps = {"Cap1", "Cap2", "Cap3"}
- -- Declare functions with local, generally good practice
- -- It's not THAT of a performance issue so if you like it for it's look
- -- then you can keep it as just 'function'
- local function onTouched(hit)
- local Character = hit.Parent
- -- Search for child inside of hit.Parent which belongs to class Humanoid
- -- This makes sure that part is limb of character or any other alive
- -- thing
- local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
- -- If hit's parent does not have humanoid, it's definitely not limb of
- -- gamer's character, return returns the function, stops it.
- if not Humanoid then
- return
- end
- for _, Child in ipairs(Character:GetChildren()) do
- if table.find(RemoveableCaps, Child.Name) then
- Child:Destroy()
- end
- end
- end
- -- :connect is deprecated, use :Connect
- script.Parent.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment