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

How to set a players spawn point on touch?

Asked by 8 years ago

I want it so when a player touches a part it will make there spawn point that part. Here's what I tried,

script.Parent.Touched:connect(function(part)
    if part.Parent:FindFirstChild("Humanoid").Health ~= 0 then
        local plr = game.Players:GetPlayerFromCharacter(part.Parent)
        plr.RespawnLocation = script.Parent
    end
end)

ERROR OUTPUT 00:21:20.546 - -bad cast-

00:21:20.547 - Script 'Workspace.Checkpoint.Script', Line 4

00:21:20.547 - Stack End

Problem, plr.RespawnLocation = script.Parent

So I'm guessing you can't use RespawnLocation to "change" the players spawn point? Do you guys know what I'm doing wrong?

1 answer

Log in to vote
1
Answered by
Wutras 294 Moderation Voter
8 years ago
-- Put this into PlayerGui
spawn = nil

function SetSpawn (spawnlocation)
    spawn = spawnlocation
end

function Respawn (plr)
    plr:LoadCharacter ()
    plr.Character.Torso.CFrame = spawn.CFrame*CFrame.new(0, 2, 0)
end

script.Parent.Parent.Character.Humanoid.Died:connect (function()
    Respawn (script.Parent.Parent)
end)

script.Parent.Parent.Character["Left Leg"].Touched:connect (function(Part)
    SetSpawn (Part)
end)

That's just an example for the understanding, hope this helps though it was written with cellphone.

0
Yeah, that cleared up a bit of confusion. Thanks! User#11440 120 — 8y
Ad

Answer this question