I want to destroy the player's player gui when he/she touches a brick. How would I do this?
COMMUNITY QUESTION
how do get the player with an ontouch event?
1 answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
