Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to set a players spawn point on touch?

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

✓ Accepted answer
-- 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.

1 comment

0

Yeah, that cleared up a bit of confusion. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.