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
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)
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
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
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.KeyUp:Connect(function(key)
if key == "r" then
game.ReplicatedStorage.Rpressed:FireServer()
end
end)
LocalScript have to go StarterGui and ServerScript have to go ServerScriptService. Also you have to add RemoteEvent in ReplicatedStorage. name is ‘Rpressed’