Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this script think that a player has a ShopGui when they don't?

So basically I was doing a shop that would pop up when the player would click a dummy in workspace. So I used a ClickDetector and made a ShopGui which I inserted in the dummy.

The Script in the dummy looks like this:

local clickDetector = script.Parent.ClickDetector
local gui = script.Parent.ShopGui

clickDetector.MouseClick:Connect(function(player)
    if not player.PlayerGui:FindFirstChild("ShopGui") then
	    print("Cloning...")
	    local clone = gui:Clone()
	    clone.LocalScript.Disabled = false
	    clone.Parent = player.PlayerGui
    else
	    print("lolwut")
    end
end)

The LocalScript in the GUI looks like this:

local gui = script.Parent.Frame
local buy = gui.Buy
local sell = gui.Sell
local exit = gui.Exit

exit.MouseButton1Click:Connect(function()
    script.Parent:Destroy()
end)

After the first time clicking the dummy the ShopGui appears in the player's PlayerGui and prints "Cloning...". Then it always prints "lolwut" no matter if the ShopGui is there or not. I'm stuck.

2 comments

0

In your else statement you could always disable and renable the gui and the script to bypass this issue. This shouldn't cause any errors because it won't run unless the gui is in the player

0

The server cannot access existing members of PlayerGui. It can only add new ones. This means that line 5 of the server script will never work properly.

1 answer

✓ Accepted answer

I believe you are cloneing in the GUI from a server script and destroying it from a localscript. This will cause the issue where the server will think the player still has the GUI because it was the CLIENT that removed it.

This discussion is preserved as it was. New answers, comments, and votes are closed.