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

Datastore not saving player data when they leave? [closed]

Asked by
Prestory 1395 Moderation Voter
6 years ago
local dataStoreService = game:GetService("DataStoreService")
local dataStore1 = dataStoreService:GetDataStore("PlayerCurrency")
strength = dataStoreService:GetDataStore("Strength")
meditation = dataStoreService:GetDataStore("Meditation")
function create(name,classname,parent)
    local it = Instance.new(classname)
    it.Parent = parent
    it.Name = name
    return it
end
game.Players.PlayerAdded:Connect(function(plr)
    local ls = create("leaderstats","Folder",plr)
    local med = create("Meditation","IntValue",ls)
    local str = create("Strength","IntValue",ls)
    str.Value = strength:GetAsync(plr.UserId) or 0
    med.Value = meditation:GetAsync(plr.UserId) or 0

game.Players.PlayerRemoving:connect(function(plr)
    dataStore1:SetAsync(plr, meditation.Value)
    dataStore1:SetAsync(plr, strength.Value)
end)
end)

Im trying to make it save the values on the leader stats when the player leaves may someone help please thanks!

0
+1 to omit moderation rep loss Goulstem 8144 — 6y

Closed as Not Constructive by Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?