Part Size Behaving Weirdly

In one of my games, you grow when touching a part, similar to growing in Agar.io, but for some reason, it acts stangely. I’ll leave code samples at the bottom.

When you die, a value is saved in your player that is your size, so lets say your size was 5, 5, 5, the value in your player would be 5, 5, 5, then when you respawn, it sets you back to that size so you don’t lose your progress. However, when your size increases again from one of the intractable items, your size goes back down to what it was before being set to 5, 5, 5.

I would say that I’ve tried some stuff, but I really haven’t. I have no idea what to do.

Resize after spawn (LocalScript):

function onDeath()
	game.Players.LocalPlayer.Size.Value = game.Players.LocalPlayer.Character.HumanoidRootPart.Size
	
	wait(0.31)
	
	for i, v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
		if v:IsA("Accessory") then
			local part = v:FindFirstChild("Handle")
			part.Size = Vector3.new(game.Players.LocalPlayer.Size.Value.X, game.Players.LocalPlayer.Size.Value.Y, game.Players.LocalPlayer.Size.Value.Z)
		end
	end
	
	game.Players.LocalPlayer.Character.Head.Size = Vector3.new(game.Players.LocalPlayer.Size.Value.X, game.Players.LocalPlayer.Size.Value.Y, game.Players.LocalPlayer.Size.Value.Z)
	game.Players.LocalPlayer.Character.HumanoidRootPart.Size = Vector3.new(game.Players.LocalPlayer.Size.Value.X, game.Players.LocalPlayer.Size.Value.Y, game.Players.LocalPlayer.Size.Value.Z)
	
	game.Players.LocalPlayer.Character.Humanoid.Died:Connect(onDeath)
end

repeat
	wait()
until game.Players.LocalPlayer.Character

game.Players.PlayerAdded:Connect(function(player)
	local size = Instance.new("Vector3Value")
	size.Name = "Size"
	size.Value = player
end)

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(onDeath)

Grow script (Inside touchable part, normal script):

local Players = game:GetService("Players")

debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true
		for i, v in pairs(hit.Parent:GetChildren()) do
			if v:IsA("Accessory") then
				local part = v:FindFirstChild("Handle")
				part.Size = Vector3.new(part.Size.X + 0.1, part.Size.Y + 0.1, part.Size.Z + 0.1)
			end
		end
		hit.Parent.Head.Size = Vector3.new(hit.Parent.Head.Size.X + 0.1, hit.Parent.Head.Size.Y + 0.1, hit.Parent.Head.Size.Z + 0.1)
		hit.Parent.HumanoidRootPart.Size = Vector3.new(hit.Parent.HumanoidRootPart.Size.X + 0.1, hit.Parent.HumanoidRootPart.Size.Y + 0.1, hit.Parent.HumanoidRootPart.Size.Z + 0.1)
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1
		script.Parent:Destroy()
	end
end)

First, I notice a few things that would trigger an error:

size.Value = player

trying to set a vector3value’s value to an instance should error, you’re also not ever setting a parent for that, so i don’t know how you would access it again.
Replacing the

repeat
	wait()
until game.Players.LocalPlayer.Character

with

if not game.Players.LocalPlayer.Character then
     game.Players.LocalPlayer.CharacterAdded:Wait()
end

is more efficient, however, I would remove the client code in this, as you’re already changing the head sizes on the server.
To make the value work, use this code on the server:

Players.CharacterAdded:Connect(function(Player)
     local Size = Instance.new("Vector3Value")
     Size.Name = "Size"
     Size.Value = Vector3.new(
          Player.leaderstats.Points.Value,
          Player.leaderstats.Points.Value,
          Player.leaderstats.Points.Value
     ) --change this to what you need
     Size.Parent = Player
     Player.CharaterAdded:Connect(function()
          Player.Character.Head.Size = Player.Size.Value -- to make the value save, 
          --update the "Size" value when you change the player's size
     end)
end)

This will make the value be as big as the player’s points. I’d recommend opening the output window in studio, so you can see errors. (top bar => view => output) To make it actually save, across different servers, you’ll need datastores, but those can come later :slight_smile: Hopefully this helped!

I probably should’ve said this, but the points and size values are almost completely unrelated. How it’s supposed to work is you start of as a certain size, then when you collect a part to become bigger, your size raises by 0.1 on each axis and you gain one point. Upon death, the spawn value will be set to your current size. When you respawn, your current size will be set to your size value.
Other notes: I know that it doesn’t do this (at least not from what I can tell), but the size is not supposed to be saved so that way people don’t take up the entire map after playing for a long time.
I would also like to scale the HumanoidRootPart and accessories, because I am trying to implement a size system where the head’s transparency is 0.99 (I’m using a StarterCharacter feature to force a character to do this with), and the accessory (which is the visible character) is replaceable so I can use it as a skin system. E.g. I replace a green hat with a red hat because they have a red skin.
If need be I can send you a .rbx file for further investigation. I would put it in here, but I’m afraid someone would use it to steal my game.

My answer should still have things to help you then. You were trying to set a vector3value to an instance, and never parented that, meaning it never set any value for the players size, and it got reset every time the player respawned. There should be errors in the console, which allow you to see what is and what isn’t working. The code was not a direct do this, but a place to get started from, as most devforum support is.

I got a weird error stating the following:
CharaterAdded is not a valid member of Player
on the line

	     Player.CharaterAdded:Connect(function()

This only occured after dying from what I could tell.

When I put Size.Value = Player in my original code, I actually meant Size.Parent = Player. I need to get better at proofreading.

Its a typo. Replace Charater with Character.