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

Part deleting after touching terrain?

x.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Part") then
				x:Destroy()
			end --Part Destroy

I have this so my my part (x) deletes after touching another part, but for some reason its also deleting after touching terrain. Maybe part and terrain are both considered parts but either way, i dont want my part to delete when touching terrain, only parts. Thanks.

1 answer

The reason for this is you do not have a system that is seeing if it is touching a player. So you part thinks that whatever it touches should be destroyed. A way to do this is finding the player and finding out if it exists. here is an example:

script.Parent.Touched:Connect(function(touched)
	local player = game:GetService("Players"):GetPlayerFromCharacter(touched.Parent)
	if player then
		script.Parent:Destroy()
	end
end)

This script checks to see if a player touched the part before deleting.

1 comment

0

You wouldn't need to check if player ~= nil. just say if player then

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