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

attempt to index local "leader" how to fix??

Asked by 5 years ago
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore ("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local leader = ("Folder")
    leader.Name = "leaderstats"
    local Cash = Instance.new("IntValue", leader)
    Cash.Name = "Cash"
    Cash.Value = ds:GetAsync(player.UserId) or 0
    Cash.Changed:Connect(function()
        ds:SetAsync(player.UserId,Cash.Value)
    end)    

    end) 

game.Players.PlayerRemoving:Connect(function(player)
    ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)

0
There are multiple things wrong with this. lunatic5 409 — 5y

1 answer

Log in to vote
1
Answered by
lunatic5 409 Moderation Voter
5 years ago

Change line from line 5 to line 8 to:

local leader = Instance.new("Folder")
leader.Parent = player
local cash = Instance.new("IntValue")
cash.Parent = leader
cash.Name = "Cash"

Also, change connect in line 4 to Connect. I'm assuming this isn't your script, so for future reference, please write your own scripts if you're going to ask questions on this website.

0
This may not even address all of the problems in your script, but it will at least fix some of them. lunatic5 409 — 5y
0
Actually set the parent last. But yes User#19524 175 — 5y
0
how is it not my script? ForgottenCollapse -8 — 5y
0
Because in previous scripts you were doing it correctly and coincidentally you're now not. Also your first question was an alvinbloxx script. User#19524 175 — 5y
0
Lol. lunatic5 409 — 5y
Ad

Answer this question