When a player dies the value of their size resets to default

Hello!
So, I am trying to make an obby game where where every 30 seconds that passes, your size increases. But i have came across a problem where if you die, your size resets back to default. So far i have tried to set the players size to value it was growing at when the player respawns, but this does not seem to work out.

Here is my code:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		local Humanoid = player.Character.Humanoid
		Humanoid.BodyDepthScale.Value = 1 --Default player parts size
		Humanoid.BodyHeightScale.Value = 1
		Humanoid.BodyProportionScale.Value = 1
		Humanoid.BodyTypeScale.Value = 1
		Humanoid.BodyWidthScale.Value = 1
		Humanoid.HeadScale.Value = 1
		Humanoid.WalkSpeed = 16
		for x = 1, 999, 1 do --For loop where x + 1 each time the loop runs
			wait(30)
			print(x) --Print in output
			Humanoid.BodyDepthScale.Value = tonumber(x) --Changing the values to x
			Humanoid.BodyHeightScale.Value = tonumber(x)
			Humanoid.BodyProportionScale.Value = tonumber(x)
			Humanoid.BodyTypeScale.Value = tonumber(x)
			Humanoid.BodyWidthScale.Value = tonumber(x)
			Humanoid.HeadScale.Value = tonumber(x)
		end
	end)
end)

And this is the solution i tried

player.CharacterAdded:Connect(function(Character)
				Humanoid.BodyDepthScale.Value = tonumber(x)
				Humanoid.BodyHeightScale.Value = tonumber(x)
				Humanoid.BodyProportionScale.Value = tonumber(x)
				Humanoid.BodyTypeScale.Value = tonumber(x)
				Humanoid.BodyWidthScale.Value = tonumber(x)
				Humanoid.HeadScale.Value = tonumber(x)
			end)

Thank You!

Is the script inside the character, or startercharacterscripts?

The script is on ServerScriptService

Create a Value that contains player size, and when use Humanoid.Died function to set his size back

1 Like

I tried what you suggested me. But now the value seems to be stuck at 1.

I tried modifying it:

game.Players.PlayerAdded:Connect(function(player)
	local size = 2 -- This
	player.CharacterAdded:Connect(function(Character)
		local Humanoid = player.Character.Humanoid
		Humanoid.BodyDepthScale.Value = size
		Humanoid.BodyHeightScale.Value = size
		Humanoid.BodyProportionScale.Value = size
		Humanoid.BodyTypeScale.Value = size
		Humanoid.BodyWidthScale.Value = size
		Humanoid.HeadScale.Value = size
		Humanoid.WalkSpeed = 16
		for x = (size-1), 999, 1 do --For loop where x + 1 each time the loop runs
			size = tonumber(x)
			print(x) --Print in output
			Humanoid.BodyDepthScale.Value = tonumber(x) --Changing the values to x
			Humanoid.BodyHeightScale.Value = tonumber(x)
			Humanoid.BodyProportionScale.Value = tonumber(x)
			Humanoid.BodyTypeScale.Value = tonumber(x)
			Humanoid.BodyWidthScale.Value = tonumber(x)
			Humanoid.HeadScale.Value = tonumber(x)
			for v=1, 3 do
				if Humanoid.Health <= 0 then
					return
				end
				wait(1)
			end
		end
	end)
end)

This works? Somehow.

I think you made the variable inside the loop

Thank you so much! Your solution worked!