The problem with your script above was that you were setting the lr value to a new player each time someone joined. It also isn't very good to have a while loop with only a tenth of a second delay. Here's what I'd recommend. You can start with the player added event which you already have.
game.Players.PlayerAdded:Connect(function()
end)
Then we can add a CharacterAdded event that fires everytime someone spawns in instead of every 0.1 seconds.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
end)
end)
And finally, we can add the code to modify the player's character.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:FindFirstChild("Humanoid")
local size = plr.leaderstats.Size.Value
if humanoid then
humanoid.BodyHeightScale.Value = size
humanoid.BodyWidthScale.Value = size
humanoid.BodyDepthtScale.Value = size
humanoid.HeadScale.Value = size
end
end)
end)
If you want the size to update whenever the values do then you can add a Changed event.
function updateSize(plr)
local char = plr.Character
if char then
local humanoid = char:FindFirstChild("Humanoid")
local size = plr.leaderstats.Size.Value
if humanoid and size then
humanoid.BodyHeightScale.Value = size
humanoid.BodyWidthScale.Value = size
humanoid.BodyDepthtScale.Value = size
humanoid.HeadScale.Value = size
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
updateSize(plr)
end)
plr:WaitForChild("leaderstats").Size.Changed:Connect(function()
updateSize(plr)
end)
end)
If you have any questions I'd be happy to answer them.
2 comments
every time a player joins, their name overrides the previous players name
so what should i do?