Hello! I am wondering if someone can see any errors in this code? I keep getting the error
tPoints is not a valid member of IntValue
yet I can’t see anything that would cause that.
I would really appreciate it if someone could find the error as it is driving me crazy…
Thanks!
local save = game:GetService("DataStoreService"):GetDataStore("Points")
local event = game.ReplicatedStorage.SaveData --remote event
---------
-- Save will be in the format: Player_USERID , points
---------
function saveInt(player, score)
if player.UserId > 0 then
save:SetAsync("Player_" .. tostring(player.UserID), score)
end
end
function loadInt(player, stat)
if player.UserId > 0 then
stat.Value = save:GetAsync("Player_" .. tostring(player.UserId))
end
end
function playerAdded(plr)
local stats = Instance.new('IntValue', plr)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
local tPoints = Instance.new("IntValue", stats)
tPoints.Name = "Total Points"
plr:WaitForDataReady()
Points.Value = 0
loadInt(plr, tPoints)
end
function playerRemoving(plr)
local stats = plr:FindFirstChild("leaderstats")
if stats ~= nil then
saveInt(plr, stats.tPoints.Value)
end
end
game.Players.PlayerAdded:Connect(playerAdded)
game.Players.PlayerRemoving:Connect(playerRemoving)