Player is not respawning at set respawn point

local checkpointFolder = workspace:WaitForChild("Fake Checkpoints")
local checkpoint = checkpointFolder:WaitForChild("Checkpoint1")
_G.runbefore = false
checkpoint.Touched:Connect(function(hit)
	if _G.runbefore == false then
		local partParent = hit.Parent
		local player = Players.LocalPlayer
		local humanoid = partParent:FindFirstChild("Humanoid")
		local realSpawnLocation = workspace:WaitForChild("RealSpawnLocation")
		if humanoid then
			realSpawnLocation.Position = Vector3.new(100,100,100)
			realSpawnLocation.Anchored = true
			player.RespawnLocation = realSpawnLocation
			_G.runbefore = true
		end
	end
end)

(Inside of a local script)

2 Likes

Try from a script. Client may not be able to set its own spawn location by design.

3 Likes

I just tried that but sadly it didn’t help, it had the same result as before.

1 Like

What does the new script look like?

Example from the docs:

local Players = game:GetService("Players")

local function addSpawn(spawnLocation)
	-- listen for the spawn being touched
	spawnLocation.Touched:Connect(function(hit)
		local character = hit:FindFirstAncestorOfClass("Model")
		if character then
			local player = Players:GetPlayerFromCharacter(character)
			if player and player.RespawnLocation ~= spawnLocation then
				local humanoid = character:FindFirstChildOfClass("Humanoid")
				-- make sure the character isn't dead
				if humanoid and humanoid:GetState() ~= Enum.HumanoidStateType.Dead then
					print("spawn set")
					player.RespawnLocation = spawnLocation
				end
			end
		end
	end)
end

local firstSpawn

-- look through the workspace for spawns
for _, descendant in pairs(workspace:GetDescendants()) do
	if descendant:IsA("SpawnLocation") then
		if descendant.Name == "FirstSpawn" then
			firstSpawn = descendant
		end
		addSpawn(descendant)
	end
end

local function playerAdded(player)
	player.RespawnLocation = firstSpawn
end

-- listen for new players
Players.PlayerAdded:Connect(playerAdded)

-- go through existing players
for _, player in pairs(Players:GetPlayers()) do
	playerAdded(player)
end

Looks similar to what you are trying to do, though they are using touch event on the spawnlocation itself.

1 Like

Instead of moving the previous spawn location I am now creating a new one and moving it, unfortunately when I run

ReplicatedStorage.UpdateCheckpoint.OnServerEvent:Connect(function(player, spawnLocation)
	print(spawnLocation)
	player.RespawnLocation = spawnLocation
	print(player.RespawnLocation)
	print(player.RespawnLocation.Position)
end)

It prints spawnLocation as Players.Magpies303
The local script is

local checkpointFolder = workspace:WaitForChild("Fake Checkpoints")
local checkpoint = checkpointFolder:WaitForChild("Checkpoint1")
_G.runbefore = false
checkpoint.Touched:Connect(function(hit)
	if _G.runbefore == false then
		local partParent = hit.Parent
		local player = Players.LocalPlayer
		local humanoid = partParent:FindFirstChild("Humanoid")
		--local newSpawnLocation = workspace:WaitForChild("RealSpawnLocation")
		workspace:WaitForChild("RealSpawnLocation"):Destroy()
		local newSpawnLocation = Instance.new("SpawnLocation")
		newSpawnLocation.Name = "RealSpawnLocation"
		newSpawnLocation.Parent = workspace
		if humanoid then
			newSpawnLocation.Position = Vector3.new(100,100,100)
			newSpawnLocation.Anchored = true
			game.ReplicatedStorage.UpdateCheckpoint:FireServer(player, newSpawnLocation)
			--player.RespawnLocation = newSpawnLocation
			_G.runbefore = true
		end
	end
end)
1 Like

FireServer doesn’t need player as first arg. That is included automatically. The handler is prob receiving {player, player, newSpawnLocation} and grabs the first two.

2 Likes

Instead of just moving spawn… I recommend just make a folder of spawn with number name. When player reaches that spawn point. A number value will get that spawnpoint’s name.

local Spawn = workspace.(FileName):FindFirstChild(NumberValue)

if Spawn then
 game.Players.LocalPlayer.Character.PrimaryPart.CFrame = Spawn.CFrame + Vector3.new(0,6,0)
1 Like

Thank you everyone!
I have solved the problem, the solution was to set all of the checkpoints as spawnlocations and then changing the spawnlocation from the server side to one of those checkpoints, I needed to make sure the checkpoints were replicated on both the server and client side which means I created them beforehand inside of the workspace.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.