Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do I get my player to delete things that touch it?

local player = game.Workspace:WaitForChild("Humanoid")
local BP = game.Workspace.Baseplate

player.Touched:connect(function(hit)
	if hit.Parent ~= player or BP then
		hit.Parent:Destroy()
	end
end)

keeps saying infinite yield possible on 'Workspace:WaitforChild("Humanoid")

and if I try to wait for the player it self it still doesnt work

2 comments

0

Instead of WaitForChild try using FindFirstChild

0

says player is a nil value

1 answer

✓ Accepted answer

I don't know why you would need this but..

Use a For Loop for Children of Player's Character. Check if Children is a Part or MeshPart. Add Touched Event. Check if hit is not Descendant of Player's Character. Destroy hit.

-- Local Script
for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
	if v:IsA("MeshPart") or v:IsA("Part") then
		v.Touched:Connect(function(hit)
			if not hit:IsDescendantOf(v.Parent) then
				hit:Destroy()
			end
		end)
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.