After you step on the Part that makes the shop open, it opens once. If you try again it won't open??
Script In Part
CanOpen = true function onTouched(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if CanOpen == true then local shop = plr:WaitForChild("PlayerGui").ShopUI.Shop shop.Visible = true CanOpen = false wait(1) CanOpen = true end end end script.Parent.Touched:connect(onTouched)
Your real problem is that you are changing the visibility from the Client and also from the Server. I think you are opening it, but then using a button to close the GUI, but that changes the visibility for the Client. The Server still sees the GUI open.
Hi! I'm lolol1901, hoping to fix your issue. Any problems? Worked? Something else? Please comment on this reply right away so I can help you or make sure it worked fine.
First of all, I suggest you replace CanOpen by debounce
, but it's 100% your choice.
Second of all, nice indent. First time I see someone using indents goodly.
Lastly, here's what I would've put in your position. This script is fully commented (like all my answers.) I'm also going to space it so it's easy to read.
db = true -- db short for debounce, replacing your CanOpen bool variable. script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") then -- Why didn't I create the player variable immediately? An accessory might've touched the part. I need to make sure whatever touched was part of a player, and if it is an accessory. local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- player var if db == true then -- Of course, an if statement to make sure the cooldown is off. db = false -- I prefer activating the cooldown first things first in case of something. local shop = player:WaitForChild("PlayerGui").ShopUI.Shop -- shop var shop.Visible = true -- Make it visible wait(1) -- Of course, wait so the debounce works. db = true -- Cooldown Over -- Small note: Make sure you have something that disables the GUI. I'm thinking you have a button inside the GUI that closes it. end end end)
Please upvote this if it is a good solution or if it worked well!
You can't access a playersgui with a normal script.
CanOpen = true function onTouched(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if CanOpen == true then local shop =game.ServerStorage.ShopUI.Shop:Clone() shop.Parent = plr.PlayerGui shop.Visible = true CanOpen = false wait(1) CanOpen = true end end end script.Parent.Touched:connect(onTouched)