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
--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
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
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