Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

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 AnonymousDeveloper13 22 — 5y
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. Gey4Jesus69 2705 — 5y

1 answer

Log in to vote
1
Answered by
vissequ 105
5 years ago
Edited 5 years ago

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.

Ad

Answer this question