How Can I make it so when I click GUI It gives me value

Here’s my code that is not giving me cash when im clicking on gui It will be great if someone can fix it!

local Players = game:GetService(“Players”)

local player = Players.LocalPlayer

game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()

player.leaderstats.Cash.Value = player.leaderstats.Caash.Value + 10

end)

Some help Would Definetly be Appreaciated :slight_smile:

1 Like

Instead of saying cash then say cash.

1 Like

I mean caash sry typo I’m not mobile

Yea, I Did that still not working I think my Coding Is all wrong.

What is the error saying? If there is any

And make sure everything is spelt correctly in if leaderstats script and tis script.

IF I change my code to this

local Players = game:GetService(“Players”)

local player = Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10

end)

then it shows this error: Players.onrecords.PlayerGui.ScreenGui.TextButton.Script:4: attempt to index nil with ‘leaderstats’

So the player is a nil at the top of it script put:

repeat wait (1) until game.Players.LocalPlayer

1 Like

Can u Copy my script and make the correct one.

Sorry I’m on mobile but at the top of the script put what I said

You can’t change a value from a localscript.

2 Likes

Ah yes! Sorry I forgot about that

Put a remote event in replicated storage

1 Like

Im in a script. But I don’t Know Why it’s not working.

That’s okay, you can use a remoteevent and then the server can change your value :slight_smile:

So far as i know MouseButton1Click isn’t a thing when you use a serverscript into a gui.

1 Like

Then remove the code and say script.Parent.mousebutton1click:connect(function()

And put that into a local script in if text button

And say game.replicatedstorage.remoteevent:fireserver()