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

Why wouldn't this work?

Asked by
thortol 22
9 years ago

saveAs = "Version BETA"

dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)

game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() wait(1) tats = player["leaderstats"]:GetChildren() for i = 1, #tats do dataStore:SetAsync(tats[i].Name,tats[i].Value) end end)

game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() wait(1) tats = player["leaderstats"]:GetChildren() for i = 1, #tats do tats[i].Value = dataStore:GetAsync(tats[i].Name) end end)

game.Players.ChildAdded:connect(function(player) local main = Instance.new("Model") main.Parent = player main.Name = "ToolsUnlocked"

local tool1 = Instance.new("BoolValue") tool1.Parent = main tool1.Name = "Dirt" tool1.Value = false

local tool2 = Instance.new("BoolValue") tool2.Parent = main tool2.Name = "Dirt" tool2.Value = false

end)

I'm trying to save the tools called 'Dirt' and 'Rock' into the inventory but its not working. I think there is something wrong with spawning the tools into the inventory.

1 answer

Log in to vote
0
Answered by 9 years ago

Well your problem is probably because you are missing a key in the DataStore.... If you want to save things in DataStore you definitely need a key which is unique to the player also don't forget to put an if statement that checks if the player has data then it will load it and if it doesn't it will set the values back to 0.... make sure your key looks something like this....

local key = "user_".. player.userId

You want to make sure the key is something unique to each player and every player has a different userId so that's how you can set up a key. I recommend you watch this video if you don't understand data store for roblox.

https://www.youtube.com/watch?v=VXcbZ2kurvk

Ad

Answer this question