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

In my game the taps is not getting registrar in the leaderstats but it is stuck on 12 help?

Asked by 4 years ago
Edited 4 years ago
01local DataStoreService = game:GetService("DataStoreService")
02local tapsStore = DataStoreService:GetDataStore("Taps")
03local starterGui = game:GetService("StarterGui")
04 
05local replicatedStorage = game:GetService("ReplicatedStorage")
06local UpdateRebirthGui = replicatedStorage.UpdateRebirthGui
07 
08 
09local event = Instance.new("RemoteEvent")
10event.Name = "AddStats"
11event.Parent = game.ReplicatedStorage
12 
13event.OnServerEvent:Connect(function(plr)
14    local taps = plr.leaderstats.Taps
15    taps.Value = taps.Value +1
View all 37 lines...

The error is between line 13-15

2 answers

Log in to vote
0
Answered by 4 years ago

You need to make the leaderstats FIRST before using the remote event. Programming languages moves from one line to the next. If the remote event tries to find leaderstats, it will result in nil because leaderstats do not exist yet. So you have to make the leaderstats first before doing the remote event.

01game.Players.PlayerAdded:Connect(function(plr) --ALWAYS make leaderstats top priority.
02    --create leaderstats
03    local is = Instance.new("Folder")
04    is.Name = "leaderstats"
05    is.Parent = plr
06    local menu = Instance.new("IntValue", is)
07    menu.Name = "Taps"
08 
09    local taps = tapsStore:GetAsync("Player_"..plr.UserId)
10    local success, errormessage = pcall(function()
11         starterGui.TapGui.Frame.counter.Text = taps   
12    end)
13    if success then
14        menu.Value = taps
15    else
View all 27 lines...
Ad
Log in to vote
0
Answered by 4 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

Yeah when your getting something from below the line your on the script won't recognize it cuz it hasn't gotten there yet.

Answer this question