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

how do i change the spawn location when it gets touched?

i want it that when a you touch another spawn part, your spawn location changes to the spawn part you touched.

local Spawn1 = game.Workspace.Spawn1
local Spawn2 = game.Workspace.Spawn2


like the first spawn is Spawn1 but when you touch Spawn2, Spawn2 will be your new spawn. Any help will help! Thanks!

1 answer

✓ Accepted answer

You can do this utilizing .Touched and the property of the player named RespawnLocation. https://developer.roblox.com/en-us/api-reference/property/Player/RespawnLocation

local Spawn1 = game.Workspace.Spawn1
local Spawn2 = game.Workspace.Spawn2

local Players = game.Players
Spawn2.Touched:Connect(function(hitPart)
	local player = Players:GetPlayerFromCharacter(hitPart.Parent) -- check if the parent of the part is a player's character (hitPart may be a leg.)

	if player then -- If it is a player
		player.RespawnLocation = Spawn2 -- Their spawn is set. Reset and try it out.
	end
end)

1 comment

0

thanks!

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