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)
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.
And I don’t think client works for server instances (It does? Idk)
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.
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)
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)