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

Weird problem with PlayerRemoving? [CLOSED] [ANSWERED]

Asked by 9 years ago

I'm trying to do a DataStorage code and the PlayerRemoving function just doesnt work. Output: 18:05:49.960 - Workspace.leaderstatsSave:36: attempt to call field 'PlayerRemoving' (a userdata value)

Code:

game.Players.PlayerRemoving(function(p)
    --SAVE--
    local DataStore = game:GetService("DataStoreService"):GetDataStore(p.userId)
    local stats = p.leaderstats:GetChildren()
    local s1 = {}
    for i=1,#stats do
        local n = stats[i].Name
        s1[n] = stats[i].Value
    end
    DataStore:SetAsync("stats",s1)
    --print("Saved "..p.Name)
end)

Help?

2 answers

Log in to vote
2
Answered by 9 years ago
game.Players.PlayerRemoving:connect(function(p) -- you need to connect the listener to a function
    --SAVE--
    local DataStore = game:GetService("DataStoreService"):GetDataStore(p.userId)
    local stats = p.leaderstats:GetChildren()
    local s1 = {}
    for i=1,#stats do
        local n = stats[i].Name
        s1[n] = stats[i].Value
    end
    DataStore:SetAsync("stats",s1)
    --print("Saved "..p.Name)
end))

0
Thanks for reminding me, I completely forgot to add :connect in front of function. TheBigCoder 25 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

MINOR MISTAKE ONLY THIS WONT BE A LENGTHY ANSWER

or will it????

You cannot call PlayerRemoving like a function, but you can use :connect on it, which you aren't.

Answer this question