I have a part that I'm moving in a building, an explosion basically. I want it to pass everything, and it does that normally. But when I added the script to kill any players it touches, it goes above the building.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Humanoid.Health = 0 table.remove(_G.foundplayers, game.Players[hit.Name]) end end)
^ in the brick
Simple error. You're attempting to index "Humanoid" from hit
rather than hit.Parent
. hit
is the potential limb that touched, while hit.Parent
is the potential Character.
Also, the second argument of table.remove
isn't the Value to remove. It is the Index of the value to remove.. you have to loop through the _G.foundplayers
table using a generic for loop. Once you find the equivalent value, use table.remove
on the given index.
Lastly, connect
is deprecated. Use Connect
!
function removePlr(p) --Iterate through foundplayers for index,value in pairs(_G.foundplayers) do if value == p then --If current val is equivalent --remove by index table.remove(_G.foundplayers, index); end end end script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then hit.Parent:FindFirstChild("Humanoid").Health = 0; removePlr(plr) end end)
Fix: Use CFrame rather than position