Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The value isnt copying can anyone help?

This isnt changing the size for some reason im so confused

wait(10)

function join(plr)
	lr = plr.Name
end
while true do
	wait(0.1)
	game.Players:WaitForChild(lr).Character.Humanoid.BodyHeightScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
	game.Players:WaitForChild(lr).Character.Humanoid.BodyWidthScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
	game.Players:WaitForChild(lr).Character.Humanoid.BodyDepthScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
	game.Players:WaitForChild(lr).Character.Humanoid.HeadScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
end


game.Players.PlayerAdded:Connect(join)

2 comments

0

every time a player joins, their name overrides the previous players name

0

so what should i do?

1 answer

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) -- Putting this just makes it so we don't have to write the same code twice. We can just define it in a function and call it whenever we need.
	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.

4 comments

0

the thing is, it's likely he wants the scale to update whenever the size updates, not just when they respawn

1

My bad, I missed that. I've added it in now.

0

that won't work because char will be nil in the Changed scope

0

Went through and refined a few things. Should work now

This discussion is preserved as it was. New answers, comments, and votes are closed.