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

DataStoreService not holding data, why, what's wrong?

Asked by 6 years ago

-- can't workout what i've done wrong...........

local DataStoreService = game:GetService ("DataStoreService") local GameData = DataStoreService:GetDataStore("storeroom")

game.Players.PlayerAdded:connect (function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats"

local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
cash.Value = 0

local rank = Instance.new("StringValue", stats)
rank.Name = "Rank"
rank.Value = "Private"


local key = "player_"..player.UserId 
local savevalues = GameData:GetAsync(key)

if savevalues then 
    cash.Value = savevalues[1]
    rank.Value = savevalues[2]
else
    local valuestosave = {cash.Value, rank.Value} 
    GameData:SetAsync (key, valuestosave)
end

end)

game.Players.PlayerRemoving:connect (function(player)

local key = "player_"..player.UserId 
local savevalues = GameData:GetAsync(key)
local valuestosave = {player.leaderstats.Cash.Value, player.leaderstats.Rank.Value}
GameData.SetAsync (key, valuestosave)

end)


secondly in a part i have the following script:-


enabled = true

script.Parent.Touched:connect (function(hit) local human = hit.Parent:FindFirstChild("Humanoid")

if human then
    local player = game.Players:GetPlayerFromCharacter (hit.Parent)
    player.leaderstats.Cash.Value = 100
    player.leaderstats.Rank.Value = "General"

    wait(2)
    enabled = false
end

end)

1 answer

Log in to vote
0
Answered by 6 years ago

The line that attempts to save your values will fail. You're not calling the SetAsync function properly, because you're missing a colon (:).

GameData.SetAsync (key, valuestosave)

should be

GameData:SetAsync (key, valuestosave)
0
thank you so much for your time. it now works dwanedibbley 10 — 6y
Ad

Answer this question