How to keep the size of Part inside player after they Respawn

I need help changing a part’s size after the player dies and this part changes size every time the player moves.

this is a almost working script that I coded, it would be a big help if anyone could fix it or find out what’s wrong with it:

local character1 = script.Parent

character1.Humanoid.HealthChanged:Connect(function(health)

	if health <= 0  then
		print("step 1")

		local cheese = character1:FindFirstChild("Cheese")

		if cheese then

			local cheeseSize = cheese:Clone()
			print("step 2")

			cheeseSize.Name = "CheeseSize_".. character1.Name
			cheeseSize.Parent = game.ServerStorage

			script.Parent = cheeseSize
			print("step 3")


			wait(6)
			character1.Cheese.Size = cheeseSize.Size
			cheeseSize:Destroy()
			script:Destroy()
			print("step 4")
		end
	end
end)
1 Like

So, is this supposed to change the size of “cheese” after the player respawns?

Is this a local or server script?

2 Likes

this is a server script so any other player can see it

1 Like

The script is pretty much resetting when the player dies, instead put it inside a CharacterAdded event inside server script in server script service.

1 Like

I attempted running your script and I don’t see the problem your talking about.
Can you clarify your issue and maybe show maybe your explorer tab (where the part is parented to and properties) plus more code if any?

2 Likes

I see that the script is inside StarterCharacterScripts

you could use the Died signal of the humanoid, so:

The script is being destroyed when the player respawns, i think u placed this wait(6) to wait for the character to respawn, instead of this, u could place the script at ServerScriptService, and do the following code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function()
		local character1 = plr.Character or plr.CharacterAdded:Wait()
		
		local oldcheese = game.ServerStorage:FindFirstChild("CheeseSize_".. plr.Name)
		
		if oldcheese then
			character1:WaitForChild("Cheese").Size = oldcheese.Size
			oldcheese:Destroy()
		end
		
		character1:WaitForChild("Humanoid").Died:Connect(function()
			local cheese = character1:FindFirstChild("Cheese")

			if cheese then
				local cheeseSize = cheese:Clone()

				cheeseSize.Name = "CheeseSize_".. character1.Name
				cheeseSize.Parent = game.ServerStorage
			end
		end)		
	end)
end)
1 Like

I use a StarterCharacter to add a extra part to the character so the part is parented to the player’s character, the script in the post is in StarterCharacterScripts
and this is the script that changes the size of the part (also in StarterCharacterScripts)

local Character = script.Parent

Character.Humanoid.Running:Connect(function(speed)

	if speed > 10 then -- Walking
		Character.Cheese.Size = Vector3.new(Character.Cheese.Size.X - .001, Character.Cheese.Size.Y - .001, Character.Cheese.Size.Z - .001)
		Character.Cheese.CheeseParticles.Enabled = true

	elseif speed == 5 then -- Walking
		Character.Cheese.Size = Vector3.new(Character.Cheese.Size.X - .0001, Character.Cheese.Size.Y - .0001, Character.Cheese.Size.Z - .0001)
		Character.Cheese.CheeseParticles.Enabled = true

	else -- Idle
		Character.Cheese.CheeseParticles.Enabled = false

	end
end)
1 Like

I see. I would suggest using Alexandre’s solution as your script does reset every time the player dies so you probably want to run it on the server.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.