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

When I test the code then nothing happens and nothing prints in the output?

Asked by 1 year ago

Code:

local Cost = script.Parent.Cost

game.Players.PlayerAdded:Connect(function(plr)
    local BuyGUI = plr.PlayerGui:FindFirstChild("BuyGUI")
    if BuyGUI then
        BuyGUI.BuyFrame.Yes.MouseButton1Click:Connect(function()
            if plr.leaderstats.Cash.Value >= Cost then
                plr.leaderstats.Cash.Value -= Cost
                print("purchase successful")    
        end
    end)
end
end)

There's no error, btw it's a normal Script

0
What is it you are trying to achieve? FireTap1 12 — 1y
0
Try wait(10) to make sure the player has fully loaded. If that worked, you can use plr.CharacterAppearanceLoaded:Connect(function()) or something like thiat. Mafincho 43 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Try waiting for the Gui. (Also be more specific on your question)

local Cost = script.Parent.Cost -- // Assuming that this is an Int/NumberValue.

game.Players.PlayerAdded:Connect(function(plr)
    local BuyGUI = plr.PlayerGui:WaitForChild("BuyGUI")
        BuyGUI.BuyFrame.Yes.MouseButton1Click:Connect(function()
            if plr.leaderstats.Cash.Value >= Cost.Value then
                plr.leaderstats.Cash.Value -= Cost.Value
                print("purchase successful")    
    end
end)
end)
Ad

Answer this question