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

2 comments
Thanks but it still didn't work. I'm trying to rescript it though so I will let you know if I fix it
Alright