HELP its been about a month my game is delayed cuz the datastore error
Can somebody fix my code to work, im trying to make a DataStore for Cash
link to repost: https://scriptinghelpers.org/questions/107002/data-store-error-plz-help-repost
Output: DS isn't a vaild part of DataModel
Thanks to anybody who fixes it!
local DS = game:GetService("DataStoreService") local CurrencySave = game.DS:GetService("FirstStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("IntValue", leaderstats) cash.Name = "Fruit" cash.Value = 100 local data local success, errormessage = pcall(function(player) data:GetAsync(player.UserId.."-cash") end) if success then cash.Value = data else print("There was an error while getting your data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall (function() CurrencySave:SetAsync(player.UserId.."-cash", player.leaderstats.Fruit.Value) end) if success then print("Player data Saved!") else print("Player Data didn't Save.") warn(errormessage) end end)
You are trying to find a child in game
called DS
and there is no such thing. You already defined the variable so, you don't need to get the Parent
again.
Change line 2 to:
local CurrencySave = DS:GetService("FirstStore")
WAIT!!
We're not done. Another error on line 2 is that you are saying :GetService()
. This can only be done on game
. You are trying to get a service in a service. It just doesn't make sense.
It should be:
local CurrencySave = game.DS:GetDataStore("FirstStore")
We're still not done.
You just added the IntValue Cash
in the leaderstats
but, on line 31, you said:
player.leaderstats.Fruit.Value
I think what you meant was:
player.leaderstats.Cash.Value
If it wasn't what you were trying to do, then please let me know.
Okay, that's it, sir!
I hope this works and make sure to accept this answer if it does!
If it doesn't, then please tell me what errors you are getting in the output.
This code is destined to work.
local DS = game:GetService("DataStoreService") local CurrencySave = DS:GetDataStore("FirstStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("IntValue", leaderstats) cash.Name = "Fruit" cash.Value = 100 local data local success, errormessage = pcall(function(player) data:GetAsync(player.UserId.."-cash") end) if success then cash.Value = data else print("There was an error while getting your data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall (function() CurrencySave:SetAsync(player.UserId.."-cash", player.leaderstats.Fruit.Value) end) if success then print("Player data Saved!") else print("Player Data didn't Save.") warn(errormessage) end end)