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)
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.
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!