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

Help with ontouched?

Asked by 10 years ago

I have this script, its meant to detect if the localplayer touches it and does something if they do.

local player = game.Players.LocalPlayer
script.Parent.Touched:connect(function (hit)
if hit.Parent == player then
player.StarterGui.examplegui:Destroy()
end
end)

however it does nothing, please help as in a rush to complete the script!

1 answer

Log in to vote
0
Answered by 10 years ago

The player is just a player object, not the item touching it. The item that is touching it is the player's character. You need to reference the character in the script, otherwise it will never work.

local player = game.Players.LocalPlayer
repeat wait() until player.Character

script.Parent.Touched:connect(function (hit)
    if hit.Parent == player.Character then
        player.PlayerGui.examplegui:Destroy() --Player does not have a StarterGui, but it's own PlayerGui.
    end
end)
Ad

Answer this question