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

Was just editing, try now & send the updated script so I can look for any issues, thanks.

it still doesnt work


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)
	
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
	
	resetBall(0.0001)
	
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

The script I provided worked on my end, likely just your script causing issues. Any errors in console?

“resetBall(0.0001)” is this a valid function? I don’t see it defined.

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)

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

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")
	task.wait(5)
	for i, v in pairs(players:GetPlayers()) do
		local humrootpart = v.Character:WaitForChild("HumanoidRootPart")
		returnToSpawn(humrootpart)
	end
	resetBall(0.0001)
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

Here’s how you’d add my script to yours, make sure everything inside the function named “score” is correct.

im tryna make it so u teleport to your original spawn when someone scores, your script should work but it somehow doesnt work for me. i made a model if u wanna review my script: GameScript - Roblox

-- TheSpecialNone 
local StarterGui = game.StarterGui
local playersService = game:GetService("Players")
local scoreBoardGui = workspace.Score.ScoreboardGui
local elfScore = scoreBoardGui.Score.SpursScore
local gnomeScore = scoreBoardGui.Score.ArsenalScore
local status = scoreBoardGui.Status
local timer = scoreBoardGui.Timer
local team = game.Teams
local RS = game.ReplicatedStorage
local RF = game.ReplicatedFirst
local SS = game.ServerStorage
local SPS = game.StarterPlayer.StarterPlayerScripts
local SCS = game.StarterPlayer.StarterCharacterScripts
local player = game.Players.LocalPlayer

local goal1 = workspace.goal1
local goal2 = workspace.goal2
local ball = workspace.TPS
local originalPosition = ball.Position

local minutes = 0
local minuteLength = 1

local function resetBall(waitTime)
	ball.Anchored = true
	ball.Position = originalPosition
	ball.AssemblyLinearVelocity = Vector3.new(0,0,0)
	ball.AssemblyAngularVelocity = Vector3.new(0,0,0)
	wait(waitTime)
	ball.Anchored = false
end

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)
	
	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
	
	resetBall(0.0001)
	
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

ball.Touched:Connect(function(part)
	if part == goal1 then
		score(gnomeScore)
		
	elseif part == goal2 then
		score(elfScore)
end
end)

for minutes=1, 400 do
	timer.Text = "Timer: " .. minutes
	status.Text = ""

	if minutes == 200 then
		
		for index, player in next, playersService:GetPlayers() do
			player:LoadCharacter()
		end
		game.ServerStorage.Balls:Clone().Parent = workspace
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
		
		status.Text = "Half Time"
		resetBall(60)
		for index, player in next, playersService:GetPlayers() do
			player:LoadCharacter()
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
			game.Workspace.Balls:Destroy()
		end
	end
	if minutes == 400 then
		for index, player in next, playersService:GetPlayers() do
			player:LoadCharacter()
		end
		game.ServerStorage.Balls:Clone().Parent = workspace
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
		status.Text = "Full Time"
		resetBall(60)
		for index, player in next, playersService:GetPlayers() do
			player:LoadCharacter()
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
			game.Workspace.Balls:Destroy()
		end
	end
	wait(minuteLength)
end

Check the most recent reply above this.

it works now, i just get teleported to a random spawn not the team spawn

Yeah.

local spawnpoint = workspace:WaitForChild("SpawnLocation")

What are the names of the team spawns?

local players = game:GetService("Players")
local redSpawnPoint = workspace:WaitForChild("RedSpawn")
local blueSpawnPoint = workspace:WaitForChild("BlueSpawn")
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)

local function returnToSpawn(rootPart, team)
	if team == "RedTeam" then
		rootPart.CFrame = redSpawnPoint.CFrame
	elseif team == "BlueTeam" then
		rootPart.CFrame = blueSpawnPoint.CFrame
	end
end

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")
	task.wait(5)
	for i, v in pairs(players:GetPlayers()) do
		local team = v.Team
		local humrootpart = v.Character:WaitForChild("HumanoidRootPart")
		returnToSpawn(humrootpart, team)
	end
	resetBall(0.0001)
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

Here, the team gets passed as an additional argument to the “returnToSpawn” function and then returns the player to the correct team’s spawn location. You will need to change the spawn point references located at the top of the script.

SpawnLocation are the names for all of them. I had them grouped before into: image

will it still work if i have them grouped? (5 spawns for A and B while the ref has 1 spawn)

I thought there were just 2 teams, you’ll need to slightly modify the script to accommodate for the 3rd team.

1 Like

This works with 1 spawn point per team. You’ll need to slightly change the script to fit the game since I used placeholder team names & spawn points.

1 Like

i will do, how would i make it so more spawns can work?

local players = game:GetService("Players")
local athleticoSpawns = workspace:WaitForChild("Athletico Spawns"):GetChildren()
local barcaSpawns = workspace:WaitForChild("Barca Spawns"):GetChildren()
local refSpawns = workspace:WaitForChild("Ref Spawns"):GetChildren()
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)

local function returnToSpawn(rootPart, team)
	if team == "Athletico" then
		local rand = math.random(1, #athleticoSpawns)
		rootPart.CFrame = athleticoSpawns[rand].CFrame
	elseif team == "Barca" then
		local rand = math.random(1, #barcaSpawns)
		rootPart.CFrame = barcaSpawns[rand].CFrame
	elseif team == "Ref" then
		local rand = math.random(1, #refSpawns)
		rootPart.CFrame = refSpawns[rand].CFrame
	end
end

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")
	task.wait(5)
	for i, v in pairs(players:GetPlayers()) do
		local team = v.Team
		local humrootpart = v.Character:WaitForChild("HumanoidRootPart")
		returnToSpawn(humrootpart, team)
	end
	resetBall(0.0001)
	game.Workspace.InvisibleWalls:Destroy()
	game.Workspace.SparksTex:Destroy()
end

Again, make sure to change the team names/spawn references if necessary. I’ve tried to match them to the game.

i changed all the team preferences and it still doesn’t work for some reason

Can you provide the modified script? Also please provide a screenshot of your explorer window including the organisation of everything, team spawns, team names etc.

This is working my end so it should be working for you if you set everything correctly.

I forgot to mark this as solution, thanks!

Would there be a way to teleport the players to a random part? (4 players are on each team max)

1 Like