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

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

Asked by 5 years ago

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)

0
That change will not replicate to the server. Do it through RemoteEvents. JakyeRU 637 — 5y
0
How do I do that? Ive never used remote events. zandefear3 0 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

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! zandefear4 90 — 5y
0
Sorry about the scripts not always showing up in text box. Sir_funnyguy 4 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
Thanks, it worked but it wont let me login to my account. zandefear4 90 — 5y
0
Nvm, having a problem saving. zandefear4 90 — 5y
0
Can you please Mark it as accepted? NickAtNick 163 — 5y

Answer this question