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

I wanted to connect my GUI to my leaderstats so when you press the button the value +10000?

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.

1 comment

0

local remote = game:GetService("ReplicatedStorage") local event = remote:WaitForChild("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",

2 answers

✓ Accepted 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)

4 comments

0

local remote = game:GetService("ReplicatedStorage") -- ?

0

I named my remote Event test I also completed the steps the only thing confusing me is that you did not how do we get the event

0

Line 24 has an error on the 1st script: player.leaderstats.NoobChips += 10000

1

Line 24 should be player.leaderstats.NoobChips.Value += 10000

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)

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