How would I make a script restart whenever the player is killed?

I have a script in my game that changes the player's size but the script doesn't work when ever the player is killed, could anyone help?

A few different ways to do this. One way would be to set the scale when the player respawns using the spawnedEvent.

Example code:

local function scale_player(player)
	if(Object.IsValid(player)) then
		player:SetWorldScale(Vector3.ONE * 2)
	end
end

Game.playerJoinedEvent:Connect(function(player)
	scale_player(player)
	player.spawnedEvent:Connect(scale_player)
end)

its easy to do! Follow the Steps Below:

  1. First Copy the Script that change the size of player
  2. Now Do like this:
Game.playerJoinedEvent:Connect(fuction(player)
player.diedEvent:Connect(function()
 --- Paste the Script in Here...
end)
end)
  1. Now you are Ready!

If you need any help, dont mind to ask :smiley: !

Thankyou for the help this will fix my game.

How would I fix this?

hey remove the line 9 and 10! no need of that

I still get an error

also no need of that function on line 5!
just do like before player.diedEvent, paste at line 6 and again paste and line inside player.diedEvent Function!

can you put together the code so I can paste it because I don't know what mean by

Here it is:

Game.playerJoinedEvent:Connect(function(player)
  player:setWorldScale(Vector3.New(propPlayerScale,propPlayerScale,propPlayerScale))

  player.diedEvent:Connect(function()
    player:setWorldScale(Vector3.New(propPlayerScale,propPlayerScale,propPlayerScale))
  end)

end)

I don't know if it's the custom properties not working but the player size doesn't change at all.

Would I need to include script:GetCustomProperty("playerScale") to make it work?

srry my mistake that s needs to be capital like this :SetWorldScale but i made it to :setWorldScale

Still no luck but I can probably try making player seam bigger by changer the camera offset.

what's the error? can u check the output and tell me ?

Everything seams to work fine but still doesn't change the player's size.

yo u r custom property is wrong! u must create a int property

image

Just tried that and still didn't work.

I just made it work again by adding this line of code


but it still stops working when the player dies.