Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

-- 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

✓ Accepted answer

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)

1 comment

0

thank you so much for your time. it now works

This discussion is preserved as it was. New answers, comments, and votes are closed.