How would i teleport a player to their original spawn location without killing them, or return them to a specific part for their team?

Hi. I am really stuck on how to teleport the player back when someone scores a goal (i just kill then in this script so they respawn)

local function score(team)
	
	print ("ball cloned xd")
	
	team.Text = team.Text + 1
	
	game.ServerStorage.SparksTex:Clone().Parent = workspace
	
	status.Text = "GOAL"
	
	game.ServerStorage.InvisibleWalls:Clone().Parent = workspace
	
	print ("ball sucsessfully went out of transparency noob")
	 
	wait (5)
	
	for index, player in next, playersService:GetPlayers() do
	player:LoadCharacter() 
	end
	
	resetBall(0.0001)
	
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

(here is the line)

for index, player in next, playersService:GetPlayers() do
	player:LoadCharacter() 
	end
3 Likes
character:SetPrimaryPartCFrame(SpawnLocation.CFrame)

Then change SpawnLocation to whatever part you want the character to teleport to

2 Likes

is it possible to do one player per team gets their own spawn? like this

image

ignore the typo, its meant to say all 4 players get teleported to a part, each with their own location.

Yes, you would probably want to store the spawn locations and which player they belong to somewhere so that you know where to teleport the player

so, I created a script, do you want to see

Edit : nevermind, these are the resources that i use

To be more specific to teleport players based on their role :
https://developer.roblox.com/en-us/api-reference/function/Instance/SetAttribute
https://developer.roblox.com/en-us/api-reference/function/Instance/GetAttribute

1 Like

yes thank you very much for ur help, i do wanna see the script

--Edit : 26/11/2021
local redSpawns = workspace.Spawns.RedSpawns --contain all the spawn parts in position for redTeam
local blueSpawns = workspace.Spawns.BlueSpawns--contain all the spawn parts in position for blueTeam

local function Teleport(players,Location)
	for i,player in pairs(players) do
		if player then
			local character = player.Character or player.CharacterAdded:wait()
			if character and character.Parent then
				local index = math.random(1,#Location)
				character:PivotTo(Location[index].CFrame + Vector3.new(0,5,0))
				table.remove(Location,index)
			end
		end
	end
end

local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do

	--Change RedTeam or BlueTeam Name to anything convenience
	if team.Name == "RedTeam" then 
		Teleport(team:GetPlayers(),redSpawns:GetChildren())
	elseif team.Name == "BlueTeam" then
		Teleport(team:GetPlayers(),blueSpawns:GetChildren())
	end

end
	

@ TheSpecialNone

1 Like

do i have to group the parts together? also it says unknown global teleport, did u define teleport or did you not? also do i call this from my server sided script or a local script?

local players = game:GetService("Players")
local spawnpoint = workspace:WaitForChild("SpawnLocation")
local plr
local char
local hmr

players.PlayerAdded:Connect(function(player)
	plr = player
	player.CharacterAdded:Connect(function(character)
		char = character
		hmr = character:WaitForChild("HumanoidRootPart")
	end)
end)

function returnToSpawn(rootPart)
	rootPart.CFrame = spawnpoint.CFrame
end

do
	task.wait(10)
	returnToSpawn(hmr)
end
1 Like

this is meant to be in a local script but my script is server sided. how would i make this work in a local script?

This would work in a server script.

1 Like

it gives this error thoimage

That’s not an error. That’s just telling you that you can define the function as a local function.

local function returnToSpawn(rootPart)
	rootPart.CFrame = spawnpoint.CFrame
end

Like this, but it isn’t required.

2 Likes

would i replace this part with your script

for index, player in next, playersService:GetPlayers() do
	player:LoadCharacter() 
	end

What’s the current script you’re using?

1 Like

my original script, nobody elses

local function score(team)
	
	print ("ball cloned xd")
	
	team.Text = team.Text + 1
	
	game.ServerStorage.SparksTex:Clone().Parent = workspace
	
	status.Text = "GOAL"
	
	game.ServerStorage.InvisibleWalls:Clone().Parent = workspace
	
	print ("ball sucsessfully went out of transparency noob")
	 
	wait (5)
	
	for index, player in next, playersService:GetPlayers() do
	player:LoadCharacter() 
	end
	
	resetBall(0.0001)
	
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

if you are confused, i got a full on script, this is the score function when a player scores

for _, v in pairs(playersService:GetChildren()) do
	local humrootpart = v.Character:WaitForChild("HumanoidRootPart")
	returnToSpawn(humrootpart)
end

unknown global return to spawn

1 Like