So, I have this "ShopGUI" script, when someone goes into the store they hit an invisible brick, and a GUI pops up. However, when they leave the store (no longer touching part), I want the GUI to disappear. How would I do this?
Here's my script
script.Parent.Touched:connect(function(touchy) local player = game.Players:GetPlayerFromCharacter(touchy.Parent) if player then if player.PlayerGui:FindFirstChild('StoreGUI') == nil then local shopGUI = game.ServerStorage.StoreGUI:Clone() shopGUI.Parent = player.PlayerGui end end end)
Use the TouchEnded function.
script.Parent.TouchEnded:Connect(function(touched) local player = game.Players:GetPlayerFromCharacter(touched.Parent) if player then end end)
Hey gitrog,
local part = script.Parent; -- The part that will be touched. part.Touched:Connect(function(obj) -- The anonymous function connected to a Touched event. local hum = obj.Parent:FindFirstChild("Humanoid"); -- Variable to check if there's a humanoid. if hum then -- Checks if there is a humanoid. local char = obj.Parent; -- Sets a variable for the character. local plr = game:GetService("Players"):GetPlayerFromCharacter(char); -- Sets a variable for the player. local plrgui = plr:WaitForChild("PlayerGui"); -- Sets a variable for the PlayerGui, where the Shop's Gui must reside local shop_gui = plrgui:FindFirstChild("THE SHOP GUI'S NAME"); -- Variable for the shop gui(If there is one); if shop_gui then -- Checks if there is a shop gui. shop_gui:Destroy(); -- Destroys the shop gui. end -- end for the shop gui if statement end -- end for the checking humanoid if statement. end) -- end for the anonymous function.
~~ KingLoneCat