I am trying to make a game where the value of points gets saved. I check in game and the points values goes from 375 to 475 and then I exit. When I load back in the points goes back to 375. I get the error "unable to cast value to function"
local DataStoreService = game:GetService("DataStoreService")
local CreditsStore = DataStoreService:GetDataStore("CreditsStore")
local saveLoop = coroutine.create(function()
while true do
wait(300)
for i,v in pairs(game:GetService("Players"):GetChildren())do
wait()
if v then
if v.Character:FindFirstChild("Humanoid") then
CreditsStore:SetAsync(v.UserId.."-CreditsStore",v.leaderstats.Points.Value)
end
end
end
end
end)
game:GetService("Players").PlayerAdded:Connect(function(plr)
local leader = Instance.new("Folder",plr)
leader.Name = "leaderstats"
local points = Instance.new("IntValue",leader)
points.Name = "Points"
pcall(function()
points.Value = CreditsStore:GetAsync(plr.UserId.."-CreditsStore") or 0
end)
coroutine.resume(saveLoop)
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
pcall(function()
CreditsStore:SetAsync(plr.UserId.."-CreditsStore",plr.leaderstats.Points.Value)
end)
end)

1 comment
The same thing is happening to me, when you get a solution, I will be here, if I do, I will comment here.