Instant respawn for obby, help needed

I’m trying to make a script where if you press “R” you will be reset, but I don’t want it to actually reset the character, I want it to teleport to the stage they are at. Basically, a smooth instant respawn.

My press “R” to reset code right now
Screen Shot 2022-04-25 at 10.29.34 AM

Normal script:

game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(character)
	
for i,v in pairs(script:GetChildren()) do 
v:clone().Parent = character
		end
	end) 
end)

Local script:

debounce = 0
m = game.Players:GetPlayerFromCharacter(script.Parent):GetMouse()
m.KeyDown:connect(function(key)
	
if key:lower() == "r" then 
	debounce = debounce + 1
		delay(0,function()
	if debounce ~= 1 then 
		debounce = 0 end
	end)
			
if debounce == 1 then
			script.Parent:BreakJoints()
		end
	end 
end)
2 Likes

I would suggest you to make a respawn system than a kill brick system, kill brick actually kills you, and in some cases, the gui will reset, so I would say make a respawn brick, rather than a kill brick

Hi, if your wanting to teleport the character to spawn you could get the part the character is already respawning at and then teleport the character to the spawn part when you press R by setting the CFrame of the humanoidrootpart to the CFrame (or position i can’t remember off the top of my head) of the spawn part.

Or if you are wanting an instant respawn you could change the respawn time in game.Players.RespawnTime

How exactly do I implement it into my script?

This is something i quickly wrote so it’s not amazing but

local players = game:GetService("Players")
local userInputService = game:GetService("UserInputService")

local localPlayer = players.LocalPlayer

userInputService.InputBegan:Connect(function(keyInput, gameProcessed)
	if keyInput.KeyCode == Enum.KeyCode.R and not gameProcessed then -- gameProcessed is false while typing and true while not typing.
		localPlayer.Character:WaitForChild("HumanoidRootPart").CFrame = localPlayer.RespawnLocation.CFrame + Vector3.new(0, 6, 0) -- also added +6 to the Y axis so you spawn slightly above the spawn (you can change this if you want to)
	end
end)

I’ve used used userinputservice instead since i’m not sure how your script currently works.

One thing to note is that you would have to set the player’s respawn location by:

local respawnLocation = workspace.RespawnLocation
game.Players.LocalPlayer.RespawnLocation = respawnLocation 

If you don’t set the players respawn location then it won’t work. The script will work as long as you replace localPlayer.RespawnLocation.CFrame with a valid part hopefully this helps

1 Like

I’m kind of getting confused. Mind helping me on discord?

You can skip (Normal script) by adding Local Script in a StarterGui

1 Like

No like he kept a kill brick in his game, and if someone touch it, they should respawn immediately, rather than waiting 5 seconds

Thats what he mean

Also aren’t you stay alive for 30 seconds game owner?

Local script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyUp:Connect(function(key)
	if key == "r" then
		game.ReplicatedStorage.Rpressed:FireServer()
	end
end)

and
ServerScript:

game.ReplicatedStorage.Rpressed.OnServerEvent:Connect(function(plr)
 plr.Character.Torso.CFrame = workspace.Checkpoints[plr.leaderstats.Stage.Value].CFrame + Vector3.new(0, 5, 0)
end)

This is example. Because I don’t know about your checkpoints Location.

i made the original but i’m not really proud of it xd

I don’t know It work. But I’m sure it will work!

Do you think ServerScript can be different for R6 and R15? Because R15 is ‘UpperTorso’ (Maybe?) R6 is ‘Torso’

Where do I put the scripts? I just woke up so I cant really think much

LocalScript have to go StarterGui and ServerScript have to go ServerScriptService. Also you have to add RemoteEvent in ReplicatedStorage. name is ‘Rpressed’

1 Like