Spawning in ground

Hello, so recently I implemented a script into my game which when you join the game a gui appears, and you have the option of a kid, teen, or parent, and on parent when you pick it everything is fine, but when you respawn with your current screen being parent this happens:


I have no idea what can cause this, I have tried moving spawn locations up, but it still seems to happen, so I am guessing this is the script. Thought I don’t know how to fix it.
Script:

print("hi")
local teamSizeIndex = {
	--your teams don’t have to be named the same way, this is just an example
	Parents = 1,
	Teens = 0.9,
	Kids = 0.85
}

local function updateSize(player)
	print("HIIIIIIIIIIIIIIIIIII 2")
	wait(0.5)
	-- give a little bit of time for things to load
	if player.Team then -- make sure the player has a team, or else the function will error
		local char = player.Character
		local size = teamSizeIndex[player.Team.Name]
		char.Humanoid.BodyHeightScale.Value *= size-- compound operators are Awesome
		char.Humanoid.BodyWidthScale.Value *= size
		char.Humanoid.BodyDepthScale.Value *= size
		char.Humanoid.HeadScale.Value *= size
	end
end

game.Players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function()
		updateSize(player)
	end)
	
	player:GetPropertyChangedSignal("Team"):Connect(function()
		print(player.Team)
		updateSize(player)
	end)
end)

Which script, please post the script if you know which one may be causing it.

I totally forgot, haha.

print("hi")
local teamSizeIndex = {
	--your teams don’t have to be named the same way, this is just an example
	Parents = 1,
	Teens = 0.9,
	Kids = 0.85
}

local function updateSize(player)
	print("HIIIIIIIIIIIIIIIIIII 2")
	wait(0.5)
	-- give a little bit of time for things to load
	if player.Team then -- make sure the player has a team, or else the function will error
		local char = player.Character
		local size = teamSizeIndex[player.Team.Name]
		char.Humanoid.BodyHeightScale.Value *= size-- compound operators are Awesome
		char.Humanoid.BodyWidthScale.Value *= size
		char.Humanoid.BodyDepthScale.Value *= size
		char.Humanoid.HeadScale.Value *= size
	end
end

game.Players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function()
		updateSize(player)
	end)
	
	player:GetPropertyChangedSignal("Team"):Connect(function()
		print(player.Team)
		updateSize(player)
	end)
end)

just move the characters position up a few studs when u change the size

1 Like

Not sure exactly what the problem is, but I did notce this. You’ll want to not call that variable char as I believe that’s a data type in lua, representing characters (indicated by char being blue). So perhaps try changing that to character instead.

Also, Is the player’s body size changing correctly, or is that part not working?

The changing size works fine. But it is just that one part on the respawn, which happens on all respawns as a grownup role.

char:MoveTo(char.HumanoidRootPart.Position + Vector3.new(0,3,0)) -- or whatever height u want to move it to

put this inside of the function where it changes the size of the character

By the way, its errors when putting in character instead.

Where would I put that line, it errored where I put it after the wait.

Oh really? Could you share the error with us?

Make sure you change all of the other char to character as well.

if player.Team then -- make sure the player has a team, or else the function will error
		local char = player.Character
		local size = teamSizeIndex[player.Team.Name]
        char:MoveTo(char.HumanoidRootPart.Position + Vector3.new(0,3,0)) -- or whatever height u want to move it to
		char.Humanoid.BodyHeightScale.Value *= size-- compound operators are Awesome
		char.Humanoid.BodyWidthScale.Value *= size
		char.Humanoid.BodyDepthScale.Value *= size
		char.Humanoid.HeadScale.Value *= size
	end
end

The whole thing:

print("hi")
local teamSizeIndex = {
	--your teams don’t have to be named the same way, this is just an example
	Parents = 1,
	Teens = 0.9,
	Kids = 0.85
}

local function updateSize(player)
	print("HIIIIIIIIIIIIIIIIIII 2")
	wait(0.5)
	-- give a little bit of time for things to load
	if player.Team then -- make sure the player has a team, or else the function will error
		local character = player.Character
		local size = teamSizeIndex[player.Team.Name]
        character:MoveTo(character.HumanoidRootPart.Position + Vector3.new(0,3,0))
		character.Humanoid.BodyHeightScale.Value *= size-- compound operators are Awesome
		character.Humanoid.BodyWidthScale.Value *= size
		character.Humanoid.BodyDepthScale.Value *= size
		character.Humanoid.HeadScale.Value *= size
	end
end

game.Players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function()
		updateSize(player)
	end)
	
	player:GetPropertyChangedSignal("Team"):Connect(function()
		print(player.Team)
		updateSize(player)
	end)
end)

EDIT: If the above works, please give the solution to @udi_g because it was his original idea.

Oops, I forgot to change the variable char. It now does not error that.

1 Like

Still throws me in the ground.

Sorry I just edited it - there was a mistake with char.

Try it again?

I already had fixed that in my script. that u gave me before you edited it and it still did not work.

But I did notice it when I first spawned it in put me in the air when I chose a team, but then on respawn it instantly put me in the ground.

use the original script, and just replace the part that i made a revision to, and everything should work

it did jump me, but after the jump it put me in the ground again.