kirda

7

Mar 17th, 2021 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. -- Define tables outside of functions, creating new table like this every
  2. -- time you hit a part would be waste of performance, better to store it
  3. -- the memory once
  4. local RemoveableCaps = {"Cap1", "Cap2", "Cap3"}
  5.  
  6. -- Declare functions with local, generally good practice
  7. -- It's not THAT of a performance issue so if you like it for it's look
  8. -- then you can keep it as just 'function'
  9. local function onTouched(hit)
  10.     local Character = hit.Parent
  11.     -- Search for child inside of hit.Parent which belongs to class Humanoid
  12.     -- This makes sure that part is limb of character or any other alive
  13.     -- thing
  14.     local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
  15.    
  16.     -- If hit's parent does not have humanoid, it's definitely not limb of
  17.     -- gamer's character, return returns the function, stops it.
  18.     if not Humanoid then
  19.         return
  20.     end
  21.    
  22.     for _, Child in ipairs(Character:GetChildren()) do
  23.         if table.find(RemoveableCaps, Child.Name) then
  24.             Child:Destroy()
  25.         end
  26.     end
  27. end
  28.  
  29. -- :connect is deprecated, use :Connect
  30. script.Parent.Touched:Connect(onTouched)
  31.  
Advertisement
Add Comment
Please, Sign In to add comment