I want to make it so that when I walk into the detector it opens a shop but I want to make it so when a child is added to PlayerGui it changes the variable so it doesn't make more shops. Here is my script:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer.PlayerGui
local Detector = game.Workspace.ShopDetector
local RS = game:GetService("ReplicatedStorage")
local ShopOpen = ("False")
Detector.Touched:Connect(function()
if ShopOpen == ("False") then
RS.Shop:Clone().Parent = game.Players.LocalPlayer.PlayerGui
end
end)
PlayerGui.ChildAdded:Connect(function()
local ShopOpen = ("True")
print (ShopOpen)
end)
PlayerGui.ChildRemoved:Connect(function()
local ShopOpen = ("False")
end)
its a local script by the way. It is in startergui. For some reason it doesn't work. It just opens a LOT of shops. I have tried writing print (ShopOpen) when a child is added and it wrote true in the output but it still made more shops. Nothing even comes up in the output. I'm certain it has something to with the if statement. Help would be greatly appreciated. Thanks!

6 comments
Thank you so much. I'm new to scripting so sorry it's really bad. I was taught to use local when writing a variable so thats why I did it. Anyways I can't thank you enough! C:
I'm happy I could help. Could you accept the answer? It helps us both if you do.
How do I accept it?
There is a button below these comments called "Accept Answer"
There is only a button that says report.
Not sure whats causing that, it may appear later.