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

Getting an error when I'm clicking on the gui thats suppose to give me money?

I dont know why its not working, this is how I've done it before. Did the code change for this or something, can someone please help? This is my script

script.Parent.MouseButton1Click:Connect(function(Player)
Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
end)

It keeps saying 21:15:13.869 - Players.protectiverobos.PlayerGui.GetMoney.Frame.TextButton.LocalScript:2: attempt to index local 'Player' (a nil value)

2 comments

0

That change will not replicate to the server. Do it through RemoteEvents.

0

How do I do that? Ive never used remote events.

2 answers

The best way of doing this is to use remote events: Make sure you insert a remoteevent into replicatedStorage.

game.Players.PlayerAdded:Connect(function(player)



local leaderstats = Instance.new('Folder')

leaderstats.Name = 'leaderstats'

leaderstats.Parent = player

  

  

local coins = Instance.new('IntValue')

coins.Name = 'Coins'

coins.Parent = leaderstats

  

  

end)

This script is what I used to create the currency Coins (your currency can be any name)

When you have created your GUI, insert a local script into the textbutton.

    script.Parent.MouseButton1Click:Connect(function()

game.ReplicatedStorage.RemoteEvent:FireServer()

end)

This will fire the remote event Now insert a script into the workspace and type the following:

    game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)

player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 -- Make coins your currency

end)

This will make it every time you click the button your currency will increase by 1.

2 comments

0

Thank you so much!!! It worked, with my datastore script. I couldnt find any other way to do it! I cant login to my account, idk why other wise I would accept it!

0

Sorry about the scripts not always showing up in text box.

Okay, first of all: This script must be on LocalScript,

Thus, 'player' is an invalid variable argument function in LocalScripts! so the script should be:

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
end)

Hope this helps!

3 comments

0

Thanks, it worked but it wont let me login to my account.

0

Nvm, having a problem saving.

0

Can you please Mark it as accepted?

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