I came across an error and since the 2 scripts are connected I will present them both.
The 1st script showed had no error but the second script had an error of : "Players.frunwiash.PlayerGui.YesGUI.StarterBoosterScript:5: attempt to index nil with 'leaderstats'
1st script :
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local NoobChips = Instance.new("IntValue", leaderstats) NoobChips.Name = "NoobChips" NoobChips.Value = 10000 local Wins = Instance.new("IntValue", leaderstats) Wins.Name = "Wins" Wins.Value = 0 local Rank = Instance.new("IntValue", leaderstats) Rank.Name = "Rank" Rank.Value = 70 end)
2nd script:
local YesGUI = script.Parent local YesButton = YesGUI.YesButton YesButton.MouseButton1Down:Connect(function() local PlayerChips = player.leaderstats.NoobChips PlayerChips.Value = PlayerChips + 10000 end)
Please help me find the solution to this answer.
First, you should be adjusting the NoobChips stat from a Server-Side script, not a LocalScript.
Second, the reason for your error in 2nd script is you never defined player anywhere in the script.
My recommendation is to use a RemoteEvent to change the leaderboard stat. Fire the event to the server when the button is pressed, and handle the increase of chips on the server.
LocalScript / 2nd script
local YesGUI = script.Parent local YesButton = YesGUI.YesButton local event = -- location of remote event YesButton.MouseButton1Down:Connect(function() event:FireServer() end)
Server-side Script / 1st script
local event = -- location of the same remote event game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local NoobChips = Instance.new("IntValue", leaderstats) NoobChips.Name = "NoobChips" NoobChips.Value = 10000 local Wins = Instance.new("IntValue", leaderstats) Wins.Name = "Wins" Wins.Value = 0 local Rank = Instance.new("IntValue", leaderstats) Rank.Name = "Rank" Rank.Value = 70 end) event.OnServerEvent:Connect(function(player) player.leaderstats.NoobChips += 10000 end)
Here is what I did for your solution
My RemoteEvent is called "Test"
Error: Workspace.LeaderStatsScript:24: attempt to perform arithmetic (add) on Instance and number - Server - LeaderStatsScript:24
The error is on the 1st script of line 24(serverside script)
1st script:
local event = game.ReplicatedStorage.Test game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local NoobChips = Instance.new("IntValue", leaderstats) NoobChips.Name = "NoobChips" NoobChips.Value = 10000 local Wins = Instance.new("IntValue", leaderstats) Wins.Name = "Wins" Wins.Value = 0 local Rank = Instance.new("IntValue", leaderstats) Rank.Name = "Rank" Rank.Value = 70 end) event.OnServerEvent:Connect(function(player) player.leaderstats.NoobChips += 10000 end)
2nd script no error:
local YesGUI = script.Parent local YesButton = YesGUI.YesButton local event = game.ReplicatedStorage.Test YesButton.MouseButton1Down:Connect(function() event:FireServer() end)