Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Could somebody help me with this script, Respawn on death location?

Asked by 6 years ago

Hello when It comes to Lua. I'm pretty bad I must say, I've also been working on a "Respawn on death location" local script, basically simply wherever on the game you die you repsawn at the place you died at.

I'll leave some code snippets of what i've tried to make this happen.


local localplayer = game.Players.LocalPlayer
local originalPos = game.Players.LocalPlayer.Character.Torso.CFrame

game:GetService("RunService").RenderStepped:connect(function()
    local Player = game.Players.LocalPlayer
    if Player.Character.Humanoid.Health == 0 then
        localplayer.Character.Torso.CFrame = localplayer.Character.Torso.CFrame
        wait(7.25)
        localplayer.CFrame = originalPos
    end    
end)

Second Code Snippet - By a unknown person, may help if you are trying to help me fix my code above


--// CONSTANTS
local Player = game.Players.LocalPlayer

--// INACTIVE VARIABLES
local Character

local DeathPos
local DeathConnection

--// DEATH POS FUNCTION
function getDeathPos()
    if Character:FindFirstChild("Torso") then 
        DeathPos = Character.Torso.CFrame

    elseif Character:FindFirstChild("HumanoidRootPart") then 
        DeathPos = Character.HumanoidRootPart.CFrame
    else
        print("No torso or humanoid found!")
    end
    DeathConnection:Disconnect(); DeathConnection = nil;
end

--// CHARACTER ADDED EVENT
Player.CharacterAdded:Connect(function(character)
    --GET VARIABLES--
    Character = character
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    --TP PLAYER TO DEATHPOS--
    if DeathPos then 
        Character.Torso.CFrame = DeathPos
    end

    --ON DEATH CONNECTION--
    if humanoid then 
        DeathConnection = humanoid.Died:Connect(getDeathPos)
    else
        print("no humanoid found!")
    end
end)

0
You should be using all local variables. On line 11 you are using a global function. connect is deprecated so use Connect as well. User#19524 175 — 6y
0
dude you don't need semicolons User#21908 42 — 6y
0
are you using R15 characters? User#16405 0 — 6y
0
convert the script I gave you into a server one hellmatic 1523 — 6y
View all comments (2 more)
0
Or you can use a easier method: make a gui button and when the player clicks it will save the CFrame and tp the player back to that pos after death hellmatic 1523 — 6y
0
You'll need remotes and server script setting the pos hellmatic 1523 — 6y

1 answer

Log in to vote
0
Answered by
Stycon 30
6 years ago

You are kind of over complicating it. You could just simply have a checkpoint follow the player two or three studs under their feet. You don't even need to have the checkpoint colliding. Just have the player step on the checkpoint as soon as they start the level, and then make the checkpoint non-colliding and have it follow the player wherever they go. (on the player's death pause the following function, as the checkpoint should be following the torso, and the body disconnects.) Anyway, i hoped this helped, and I'm sorry if this was not what you were looking for. Have a nice day!

Ad

Answer this question