Character sometimes not able to respawn

Hey everyone.

I’ve been working on a new game, but im stuck at a very serious issue that I can’t seem to figure out. I didn’t know what catagory to put this in, but this seemed the most reasonable. Hoping someone here can enlighten me but let me explain the issue.

So last night while testing my game, I noticed that when the player dies to a kill brick, there is a small chance that the player doesn’t respawn, the camera rotates 180 degrees, and the player can keep rotating their camera, not move, only rotate. If the player tries to respawn, the camera would just flip and they wouldn’t repsawn. The game uses a checkpoint system to respawn, code below. I’ve tried to change the system to a different script, yet the issue still appeared. I also tried to change the kill brick code, yet no luck. Now today, I haven’t changed anything about the game, but I can’t replicate the issue. I am still worried though that it can happen. I also do not have any scripts that run anything when players die.

Checkpoint Code:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local checkpoint = script.Parent

function onTouched(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Folder")
			checkpointData.Name = "CheckpointData"
			checkpointData.Parent = ServerStorage
		end
		
		local userIdString = tostring(player.UserId)
		local checkpointValue = checkpointData:FindFirstChild(userIdString)
		if not checkpointValue then
			checkpointValue = Instance.new("ObjectValue")
			checkpointValue.Name = userIdString
			checkpointValue.Parent = checkpointData
			
			player.CharacterAdded:connect(function(character)
				wait()
				local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
				character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
			end)
		end
		
		checkpointValue.Value = checkpoint
	end
end

checkpoint.Touched:Connect(onTouched)

If anyone can help me find out what could be possible issues as what could cause what I describle, please let me know. Thank you.

What are you trying to do here:

player.CharacterAdded:connect(function(character)
	wait()
	local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
	character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
end)

And, why is it inside a Touched event?

1 Like

I am not sure to be honest. I followed a guide from this post: Obby Checkpoint Tutorial For Noobs. I am not good at making checkpoints, and im still learning how to code.

I was also able to recreate it, but I found that it usually only happens in Roblox app. I’ve been trying in studio for a while but can’t recreate it, but in Roblox app it happens more often. I also was able to respawn this time, unlike other times when nothing would happen.

Video

As far as resetting a spawn point, you can just do something like:

local Players = game:GetService("Players")

local function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if not player then return end
		player.RespawnLocation = checkpoint -- if checkpoint is an actual SpawnLocation (not a part)
	end
	
end
checkpoint.Touched:Connect(onTouched)

I am not sure about the rest of the script - as in - I am not sure what you are trying to accomplish with it.

I can’t seem to replicate your issue. But, my best guess is to force respawn the character every time they die, so hopefully they will respawn no matter what. Just place this code after the player.CharacterAdded function, and it should be ready to use.

player.Character.Humanoid.Died:Connect(function()
	task.wait(Players.RespawnTime)
			
	player:LoadCharacter()
end)

Okay sounds like a good solution. I’ll try this tomorrow when I have time and I’ll mark it as solution if it works. Thank you!