How would you make a script that would not allow players to respawn when they die until they click a button?

NOTE: I am NOT asking for entire scripts, I just need assistance on this topic, also, I cannot post in discussions yet.

Hello I am Kamlkaze_Kid. Anyway, I was making a story game, trying to figure out how to do make a script that would not allow players to respawn when they die until they click a button. Do you have to mess with the player scripts? If you have questions please ask.

1 Like

Hey there!
Firstly you will need to check CharacterAutoLoads as false (CharacterAutoLoads is a property of Players service.) Then you will be firing a RemoteEvent to server when player presses your respawn button. The server will be listening for the RemoteEvent getting fired and whenever it is fired, you should check if the player is actually dead (by Humanoid.Health) (to prevent exploiters getting respawned if they aren’t dead) and then respawn the player who fired the event with Player:LoadCharacter().
I hope this helped!

4 Likes

What is CharacterAutoLoads do? I want to learn it, so I know in future times.

1 Like

Pretty sure when character auto loads is off your character doesn’t automatically spawn.

1 Like

So it just delays it, or the character doesn’t spawn at all?

1 Like

Your character just doesn’t spawn at all.

1 Like

Actually it only delays it (I turned it of when i join the game otherwise your character doesn’t load at all), (I just tested it out) is it ok to use the change RespawnTime property in a script instead?

1 Like

Hmmm, I just tested in an empty baseplate and it doesn’t just delay it, my character never spawned. You must have some other scripts in your game that spawned your character. Changing the respawn time would also work, although the reset button would still kill you, you just wouldn’t respawn.

1 Like

i usually disable the Death state using Humanoid:SetStateEnabled() and then when the button is clicked Re-enable it and set it state to the Death State using Humanoid:ChangeState() cuz it may be that the Player regenerated health

3 Likes

I tried this but it didn’t work…

       '''
     P = script.Parent.Parent.Parent.Parent.Character.Humanoid 
     while true do 
     wait(0.1) 
     if P.Health == 0 then 
     script.Parent.Visible = true 
     game.Players.RespawnTime = 9999999999999999999999999999999999999
     end
     wait()

end
‘’’

1 Like

But then if i change it in properties it works

1 Like

Is that a local script? It needs to be a server script. Also that wouldn’t work well, because that respawn time would change for everyone. try what @LukaDev_0 said.

How do you access humanoid, when i try it shows an error

its inside the Character.

Also, i’m reading Players.CharacterAutoLoads’s documentation and it says the character won’t spawn until u tell it to

so like

      '''
          game.Players.LocalPlayer.Character.Humanoid

           '''

?

Yes. Must be a localscript too

i edited my previous post

game.Players.LocalPlayer.Character.Humanoid:SetStateEnabled()

like this?

The first parameter of SetStateEnabled is the humanoid state type, the second parameter is whether it should be enabled or not.

-- Disables the death state
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Death, false)

is this a local script or a server script

It needs to be local. Keep it in starter player scripts.