game.Players.PlayerAdded:Connect(function(player) print(player.Name.."has joined") local Cash = player:WaitForChild("leaderstats").Cash.Value if Cash then print("foundCash") script.Parent.MouseButton1Click:Connect(function() print("ClickedBuy") local price = script.Parent.Parent.Price.Value if Cash >= price then print(">=") end end) end end)
If this is a server script, you would have to put it into a local script,
and at the beginning don't put "player" after function because you have game.Players.LocalPlayer
Edit: I just realized another error in your code. When you say:
local price = script.Parent.Parent.Price.Value
You should have said:
local price = script.Parent.Parent.Price
And instead of:
if Cash >= price then
You would do:
if Cash >= price.Value then
You would do the same thing with the cash variable, and in the end, it would look like this.
local player = game.Players.LocalPlayer local Cash = player:WaitForChild("leaderstats").Cash if Cash then print("foundCash") script.Parent.MouseButton1Click:Connect(function() print("ClickedBuy") local price = script.Parent.Parent.Price if Cash.Value >= price.Value then print(">=") end end) end
You can copy and paste if you want.
You have to separate server code from GUI code. The server should (as you have there) be making sure that the player has enough money - but it shouldn't be directly responding to the player pressing a button. Your GUI code should use a RemoteEvent to inform the server of the player's wishes; the server should then confirm that the player can do that.
Resources:
Also note that server scripts don't run when placed in StarterGui - they can be in the workspace or ServerScriptService, see https://developer.roblox.com/api-reference/class/Script