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

how do get the player with an ontouch event?

Asked by 9 years ago

I want to destroy the player's player gui when he/she touches a brick. How would I do this?

1 answer

Log in to vote
0
Answered by
Dominical 215 Moderation Voter
9 years ago

You would use an argument and a if statement in your Touched function. Put the name as a string stored in the GuiName variable and make sure to put this script inside of the brick!

GuiName = "NAME OF SCREENGUI HERE" -- Put the name of the Gui here. (Caps Sensitive)


function onTouched(hit)
   if game.Players:GetPlayerFromCharacter(hit.Parent) then
 if  game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui:findFirstChild(GuiName) then
game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui:findFirstChild(GuiName):Destroy()
end
end
end

script.Parent.Touched:connect(onTouched)
Ad

Answer this question