I have a saving script that saved my data the first time but would not the next times. So I can tell that the problem is overwriting data. I even put in a anew thing to save and it saved it once but would not the next time. Thanks in Advance. Also someone on my last one said,"because the player is in the players service , not workspace" can someone tell me if that is correct and if so tell me what they mean by that.
Here is my Script I put into "ServerScriptServicee" I have another script that creates everything being saved in this script
local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("-xBuckDatax-") -- This function saves the players data local function Save(player) local key = local key = game.Players:WaitForChild(player).UserId local plr = workspace:WaitForChild(player.Name) local save = { ["SeerBux"] = player.leaderstats["SeerBux"].Value, ["SpdWaitTime"] = player.WaitTime.WaitTimeSpd.Value, ["StrWaitTime"] = player.WaitTime.WaitTimeStr.Value, ["walkSpeed"] = plr:WaitForChild('Humanoid').WalkSpeed, ["customize"] = player.Customize.Value, ["Exp"] = player.leaderstats.ExperiencePts.Value, ["level"] = player.leaderstats.Level.Value, ["SpdCheck"] = player.SpdCheck.Value, ['energy'] = player.EnergyCount.Value, ['enbool'] = player.EnergyBool.Value } --saves their key and money to the data store local success, err = pcall(function() DataStore:SetAsync(key, save) end) if not success then warn("Failed to over-write data"..tostring(err)) return end end -- This function loads the players data local function Load(player) -- saves the player Id as key local key = player.UserId local plr = workspace:WaitForChild(player.Name) local moneyAlready local success, err = pcall(function() moneyAlready = DataStore:GetAsync(key) end) if not success then warn("Failed to read data"..tostring(err)) return end if moneyAlready then player.leaderstats.SeerBux.Value = moneyAlready.SeerBux player.WaitTime.WaitTimeSpd.Value = moneyAlready.SpdWaitTime player.WaitTime.WaitTimeStr.Value = moneyAlready.StrWaitTime plr:WaitForChild('Humanoid').WalkSpeed = moneyAlready.walkSpeed player.Customize.Value = moneyAlready.customize player.leaderstats.ExperiencePts.Value = moneyAlready.ExperiencePts player.leaderstats.Level.Value = moneyAlready.Level player.SpdCheck.Value = moneyAlready.SpdCheck player.EnergyCount.Value = moneyAlready.energy player.EnergyBool.Value = moneyAlready.enbool else Save(player) end end game:BindToClose(Save) Players.PlayerAdded:Connect(Load) Players.PlayerRemoving:Connect(Save)
Here's the leaderboard script in case you wanted it. Not everythin here is saved. I just use this script to create Values, animations, etc. in game.
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local humanoid = char:WaitForChild("Humanoid") local animate = char:WaitForChild("Animate") local ls = Instance.new("Folder", player) ls.Name = "leaderstats" local stats = Instance.new("Folder", player) stats.Name = 'Stats' local Cash =Instance.new("IntValue", ls) Cash.Value = 1000 Cash.Name = "SeerBux" local level = Instance.new("IntValue", ls) level.Name = "Level" level.Value = 1 local Custom = Instance.new("BoolValue", player) Custom.Name = "Customize" Custom.Value = false local waittimeFold = Instance.new("Folder", player) waittimeFold.Name = 'WaitTime' local waittimespd = Instance.new("IntValue", waittimeFold) waittimespd.Name = 'WaitTimeSpd' waittimespd.Value = 3 local exp = Instance.new("IntValue", ls) exp.Name = "ExperiencePts" exp.Value = 0 local waittimeStr = Instance.new("IntValue", waittimeFold) waittimeStr.Name = 'WaitTimeStr' waittimeStr.Value = 3 local power = Instance.new("IntValue", stats) power.Name = "Power" power.Value = 5 local energy = Instance.new('IntValue', player) energy.Name = 'EnergyCount' energy.Value = 22 local boolenergy = Instance.new('BoolValue', player) boolenergy.Value = true boolenergy.Name = 'EnergyBool' local usebool = Instance.new('BoolValue', player) usebool.Name = 'EnergyUsed' usebool.Value = false local lift = Instance.new('StringValue', workspace.Animations) lift.Name = 'Lift' local liftanim = Instance.new('Animation', lift) liftanim.Name = 'LiftAnim' liftanim.AnimationId = 'http://www.roblox.com/asset/?id=2914392738' end) end)
I got two spots that might be it:
line 40: local moneyAlready :Where is what it equals?
line 3: Invalid datastore? (-xBuckDatax-)
Was testing your code myself, found these.
["Exp"] = player.ExperiencePts.Value,
In your load/save script and then in your leaderstats,
local exp = Instance.new("IntValue", ls) exp.Name = "ExperiencePts"
the leaderstats defining experiencePts as being a child of leaderstats, while in the load you are caling it as directly under player. Not sure if this is the only issue, but this is one. Which would be stopping much of your code from running properly.
You should also check the other values to see if any of them are affected by the same issue.
It means you've apparently attempted to reference the workspace, though instead referenced the Players Service; indexed 'Players'.
I believe what the person was trying to inform you about was getting the Character. Don't attempt to find it by looking for it in workspace, if there is another Instance with an identical handle, it can potentially return an unanticipated Object.
Simply write: local Character = Player.Character or Player.CharacterAdded:Wait()
*for a more accurate and direct route.
Though I believe this isn't the case and that you were actually trying to reference the PlayerInstance
. In this case, the person that informed you was correct–PlayersInstances reside in the Players Service.
To properly Index the PlayerInstance
, you need to reference it as a Child of said Service, this can simply be accomplished by writing Players.LocalPlayer
–to retrieve the local Client–Players:GetPlayerFromCharacter(instance Character)
–preform a reverse search–and Players[Instance.Name]
; however this method specifically is more case sensitive.