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

Value not being created, and other value being created as intvalue?

Asked by 3 years ago

So im making a datastore that saves the players leaderstats data but for some reason its not working. Because for some unknown reason the AFKTime value is not being created. and my Rank Value is being created as a integer value rather then a stringvalue

Code: (Server script in ServerScriptService)

local DataStoreService = game:GetService("DataStoreService")
local AFKTimeData = DataStoreService:GetDataStore("AFKTimeData")





game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"

    local AFKTime = Instance.new("IntValue")
    AFKTime.Parent = leaderstats
    AFKTime.Name = "AFKTime"
    AFKTime.Value = 0

    local Rank = Instance.new("StringValue")
    AFKTime.Parent = leaderstats
    AFKTime.Name = "Rank"
    AFKTime.Value = "Active"

    local PlayerId = "Player_"..player.UserId

    -- Data Loading System

    local data
    local success, errormessage = pcall(function()
        data = AFKTimeData:GetAsync(PlayerId)   

    end)

    if success then
        AFKTime.Value = data.AFKTime
        Rank.Value = data.Rank
    else
        print("An Error occurred")
        warn(errormessage)
    end

end)

game.Players.PlayerRemoving:Connect(function(player)
        local PlayerId = "Player_"..player.UserId

    local data = {
        AFKTime = player.leaderstats.AFKTime.Value,
        Rank =  player.leaderstats.Rank.Value
    }
    local success, errormessage = pcall(function()
        AFKTimeData:GetAsync(PlayerId, data)
    end)

    if success then
        print("Data Successfully saved")
    else
        print("An Error occurred while saving data")
        warn(errormessage)
    end

end)

1 answer

Log in to vote
1
Answered by 3 years ago

Between lines 19 and 22, you use the wrong variable.

0
oh googlpeopel15 55 — 3y
Ad

Answer this question