So I was building a simulator and randomly my code showed an error that said "leaderstats is not a valid member of Player". When clicking on it it brings to a server script in ServerScriptService that adjusts the players size when you click.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(Character) local Humanoid = Character:FindFirstChild("Humanoid") player.Character.Humanoid.BodyDepthScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.BodyHeightScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.BodyWidthScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.HeadScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.leaderstats.Strength.Changed:connect(function() player.Character.Humanoid.BodyDepthScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.BodyHeightScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.BodyWidthScale.Value = player.leaderstats.Strength.Value/300 + 0.2 player.Character.Humanoid.HeadScale.Value = player.leaderstats.Strength.Value/300 + 0.2 end) end) end)
And there was another error showing the same message. Clicking on the message sent me to a Local Script in StarterGui (the local script is in a text label which is in screengui in startergui) The Local Script code is under.
strength = game.Players.LocalPlayer.leaderstats.Strength script.Parent.Text = "Strength: "..strength.Value strength.Changed:connect(function() script.Parent.Text = "Strength: "..strength.Value end)
I checked all my code and I'm sure that the problem was produced in the server script in ServerScriptService called "datastore" since that's where the Instance.new("IntValue") is made
local datastore = game:GetService("DataStoreService") local data1 = datastore:GetDataStore("StrengthData") local data2 = datastore:GetDataStore("RebirthData") game.Players.PlayerAdded:connect(function(plr) local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local rebirths = Instance.new("IntValue", leaderstats) rebirths.Name = "Rebirths" local strength = Instance.new("IntValue", leaderstats) strength.Name = "Strength" strength.Value = data1:GetAsync(plr.UserId) or 0 data1:SetAsync(plr.UserId, strength.Value) rebirths.Value = data2:GetAsync(plr.UserId) or 0 data2:SetAsync(plr.UserId, rebirths.Value) game.Players.PlayerRemoving:connect(function() data1:SetAsync(plr.UserId, strength.Value) data2:SetAsync(plr.UserId, rebirths.Value) end) end)
I tried changing plr to player, I tried using print(leaderstats.Parent) but it didn't print anything so I don't know how to fix this. Any help would be appreciated.
Edit: I was using a simulator kit (Tryanime's Simulator Kit) so I just have to re-use the kit so I just have to add the GUI changes without changing scripts. I'll let you know if other errors pop up
Try using this datastore I just made it took me like 10 mins but no problem. ds2 is way easier to use when it comes to datastore
local ds2 = require(1936396537) local plrs = {} function playeradded(player) local rebirth = ds2("Rebirths", player) local strength = ds2("Strength", player) game.Players.PlayerAdded:Connect(function(plr) local Stats = Instance.new("IntValue",plr) Stats.Name = "leaderstats" local rebirth = Instance.new("NumberValue",rebirth) rebirth.Name = "Rebirths" rebirth.Value = 0 local strength = Instance.new("NumberValue", strength) strength.Name = "Strength" strength.Value = 0 end) end function save (player) local rebirth = ds2("Rebirths", player) local strength = ds2("Strength", player) rebirth:Set(player.leaderstats.rebirth.Value) strength:Set(player.leaderstats.strength.Value) end game.Players.PlayerRemoving:Connect(function(player) save(player) end) game.Players.PlayerAdded:Connect(function(player) table.insert(plrs, #plrs +1, player.Name) playeradded(player) end) function check(tbl, thing) for i, v in pairs (tbl) do if v == thing then return true end end end for i, v in pairs(game.Players:GetPlayers()) do if not check(plrs, v.Name) then table.insert(plrs, #plrs +1, v.Name) playeradded(v) end end
I also remade the UI changer
script.Parent.Text = ''..sortText(game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Strength").Value) game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Strength").Changed:Connect(function(val) script.Parent.Text = ' '..sortText(val) end)
Hope this works and make sure to accept it if it does