Datastores Issue: not a valid member of IntValue

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… :sad:

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)
2 Likes

Why isn’t leaderstats a folder?

That’s what an example showed me. It worked before.

1 Like

Try using a folder for this.
Most of the tutorials I’ve seen use the folder for leaderstats and it works. Also, you shouldn’t supply the second argument in Instance.new(). See this thread for more details.

Thanks, I fixed it up a bit but that wasn’t the problem. I’ll post the solution I just found below.

There ended up being 2 issues.
Issue 1:
saveInt(plr, stats["Total Points"].Value) – the name was different than the variable name

Issue 2:
save:SetAsync("Player_" .. tostring(player.UserId), score) – lowercase ID

2 Likes