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

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

Asked by 3 years ago

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.

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", frunwiash 2 — 3y

2 answers

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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)
0
local remote = game:GetService("ReplicatedStorage") -- ? frunwiash 2 — 3y
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 frunwiash 2 — 3y
0
Line 24 has an error on the 1st script: player.leaderstats.NoobChips += 10000 frunwiash 2 — 3y
1
Line 24 should be player.leaderstats.NoobChips.Value += 10000 appxritixn 2235 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question