Team Respawn Issue

Hey guys,

In my round system, I’m trying to make a specific team (Offence) respawn at their original teleport location upon character death. However, they end up respawning in the Lobby spawn. How would I fix this? My thinking leads me to believe it has to do with StarterCharacterScripts, so I’ve attached a local script from there on this topic.

Here is the script for critique:

local Player = game:GetService("Players").LocalPlayer

local Workspace = game.Workspace
local Gamespawns = Workspace.GameSpawns
local OffenceSpawns = Gamespawns.OffenceSpawns:GetChildren()

Player.CharacterAdded:Connect(function(Character)
	print(Character)
	print(Player)
	if Player.Team.Name == "Offence" then
		local HRP = Character:WaitForChild("HumanoidRootPart")
		task.wait(0.1)
		local Rand = Random.new()
		HRP.CFrame = OffenceSpawns[Rand:NextInteger(1, #OffenceSpawns)].CFrame + Vector3.new(0,5,0)
	end
end)
1 Like

For client script, you should do local Character = Player.Character or Player.CharacterAdded:Wait()

Thanks for the insight. I’ve conducted a series of tests where the line is included inside/outside the function, yet the result remains the same.

Anything else?

For some reason, I rewrite your entire script on a Server Script which I put it on ServerScriptService right below here.

local Workspace = game.Workspace
local Gamespawns = Workspace.GameSpawns
local OffenceSpawns = Gamespawns.OffenceSpawns:GetChildren()

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		print(Character)
		print(Player)
		if Player.Team.Name == "Offence" then
			local HRP = Character:WaitForChild("HumanoidRootPart")
			task.wait(0.1)
			local Rand = Random.new()
			HRP.CFrame = OffenceSpawns[Rand:NextInteger(1, #OffenceSpawns)].CFrame + Vector3.new(0,5,0)
		end
	end)
end)

*Note : I was thinking that your explorer looks like below.
image

And I don’t think client works for server instances (It does? Idk)

It should still work fine using a LocalScript.

Trying to move the avatar by overwriting its position often won’t get you the desired result. Consider using Charater:MoveTo(Vector3) for better results. Let me know if that doesn’t work.

1 Like

I’m unfamiliar with moving players/parts using Vector3, but I adapted my script with the MoveTo function.

Issue still persists, so please let me know where I went wrong.

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Workspace = game.Workspace
local Gamespawns = Workspace.GameSpawns
local OffenceSpawns = Gamespawns.OffenceSpawns:GetChildren()

Player.CharacterAdded:Connect(function()
	if Player.Team.Name == "Offence" then
		
		local HRP = Character:WaitForChild("HumanoidRootPart")
		task.wait(0.1)
		local Rand = Random.new()
		Character:MoveTo(OffenceSpawns[Rand:NextInteger(1, #OffenceSpawns)])
		
	end
end)

Are you being given any errors in output, or is it just not working?

No errors at all, and the player returns to the Lobby spawn instead of either of the two Offence teleport locations.

What if you try this:

local Workspace = game.Workspace
local Gamespawns = Workspace.GameSpawns
local OffenceSpawns = Gamespawns.OffenceSpawns:GetChildren()

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		print(Character)
		print(Player)
		if Player.Team.Name == "Offence" then
			local HRP = Character:WaitForChild("HumanoidRootPart")
			task.wait(0.1)
			local Rand = math.random(1,#OffenceSpawns)
			HRP.CFrame = OffenceSpawns[Rand].CFrame * CFrame.new(0,5,0)
		end
	end)
end)
2 Likes

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