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

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

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

2 comments

0

What is it you are trying to achieve?

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.

1 answer

✓ Accepted answer

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)

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