How to have objects respawn when a player dies & respawn?

Is there a nice clean to have any objects respawn when I character respawn ?

For example:
A coin or enemy respawns when the player dies & respawn

2 Likes

Player.CharacterAdded event maybe.

Is this multi player setting, are the objects player specific, i.e. would one player spawning items spawn stuff for another player.

My mistake on it not being specific. This will be a local event.

Then simply calling a script from that event to check
If not inGame, then spawn
For each respawning object

Each time the characteradded event fires should be good. It fires on join and each respawn.

Basically What I did was have a script that removes everything but when you respawn all enemies or items would come back.

Inside the script put:

repeat wait() until script.Parent.Humanoid

game.Workspace.RespawnedStuff:ClearAllChildren()

for i,v in pairs(game.ReplicatedStorage.StuffToRespawn:GetChildren()) do
	v:Clone().Parent = game.Workspace.RespawnedStuff
end

image

Position all models in there location then put them in the folder “StuffToRespawn”

3 Likes

Hey, this script is working amazingly, but it only works globally, when I use the local script. It the objects respawn, but any scripts within it don’t function like the global setting

If the client is spawning the stuff, it will not replicate to the server.

You will want the server to do the spawning, so if you want the client to listen for respawn, you will need to fire a remote event to trigger the item spawn.

How can I code the remote event, because when I do. I get the same issue …

So first why do you need the client to spawn the things?
Why not just run it all from server?

I’m relevantly new in this area of coding, I don’t know the proper events to code it, and most of the attempts end up errors.