Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Part deleting after touching terrain?

Asked by 6 years ago
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

Log in to vote
1
Answered by
uhTeddy 101
6 years ago
Edited 6 years ago

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.

0
You wouldn't need to check if player ~= nil. just say if player then User#19524 175 — 6y
Ad

Answer this question