I am having trouble saving data. When I run it states "Unable to cast value to function".
local DataStoreService = game:GetService("DataStoreService")
local PointsStore = DataStoreService:GetDataStore("PointsStore")
local SaveLoop = coroutine.create(function(plr)
while true do
wait(120)
PointsStore:UpdateAsync(plr.UserId,plr.leaderstats.Points.Value)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue",leaderstats)
Points.Name = "Points"
Points.Value = PointsStore:GetAsync(player.UserId.."-Points") or 0
coroutine.resume(SaveLoop,player)
end)
game.Players.PlayerRemoving:Connect(function(player)
PointsStore:UpdateAsync(player.UserId.."-Points",player.leaderstats.Points.Value)
end)

1 comment
Do you think you could use print statements to find where this error derives from? Also, you seem to be overusing UpdateAsync in my experience.