Hi,
Ive noticed on my game when a player on any type of team is killed, they always spawn from the sky in the same position. Is there a way to change this position, or even better teleport this player to a certain area if they have been killed? - I tried a form of this but it didn’t seem to work.
Thanks
You will most likely want to create a spawn location and then teleport players where you want them to be to make managing players easier. (Using default spawn areas isn’t favourable)
To do this you will want to create a spawn area that isolated from the rest of the game and then teleport the character. This means that most of the time the player wont even get a chance to see the spawn area. It would be wise to have something in the spawn area for in-between games or if a player does mysteriously end up there.
here would be a rough draft up using folders containing spawns for each team (CFrame values). This means you need to properly set the teams but other than that this script would be entirely server sided so wouldn’t be exploitable and should run smoothly.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
local SpawnPositions = game.workspace:FindFirstChild(tostring(Player.Team) .. "Spawns")
Char:WaitForChild("Head")
Char.Head.CFrame = SpawnPositions[math.random(1,#SpawnPositions)].Value
end)
end)
I tried doing that in one of my scripts (teleporting the player to a set of spawnpoints i created) But it didn’t seem to work. Can you verify the syntax that would come before teleporting the players?
e.g if player:Died etc. (Along them lines)
Thanks
Actually hold on let me attempt something with teleporting players with a specific tag and see if that works (Il let you know if not) and thanks for the above code suggestion il try that if rhe tag setup doesnt work!
You don’t want to teleport a dead player. That just means they would respawn after their character reloads. Instead you want to teleport the character after respawning.
Heres something to note
Character death - When the character dies the old character is completely removed from the workspace then a new character is assigned to the player so any functions that found the character before will be broken unless updated with an event.
Knowing this, this here is your means of getting when a character has ‘respawned’
Use a custom respawn script
Example script (disable CharacterAutoLoads property of Players):
local _RespawnTime = 5
local _RespawnPoint = CFrame.new(0, -100, 0)
local _CharacterAutoLoads = true
local PlayerRespawnData = {}
local Folder = Instance.new("Folder")
Folder.Name = "Exports"
Folder.Parent = script
local Exports = {
["SetRespawnPoint"] = function(args)
local RespawnPoint = args[1]
local UserId = args[2]
if typeof(RespawnPoint) == "Instance" then
if RespawnPoint:IsA("BasePart") then
RespawnPoint = CFrame.new(
RespawnPoint.Position.X,
RespawnPoint.Position.Y,
RespawnPoint.Position.Z
)
end
elseif typeof(RespawnPoint) == "Vector3" then
RespawnPoint = CFrame.new(
RespawnPoint.X,
RespawnPoint.Y,
RespawnPoint.Z
)
elseif typeof(RespawnPoint) == "CFrame" then
else
error("Invalid Argument Supplied")
end
if PlayerRespawnData[UserId] ~= nil then
PlayerRespawnData[UserId]["RespawnPoint"] = RespawnPoint
return true
else
PlayerRespawnData[UserId] = {
["RespawnTime"] = _RespawnTime,
["RespawnPoint"] = RespawnPoint
}
return true
end
end,
["SetRespawnTime"] = function(args)
local RespawnTime = args[1]
local UserId = args[2]
if PlayerRespawnData[UserId] ~= nil then
PlayerRespawnData[UserId]["RespawnTime"] = RespawnTime
return true
else
PlayerRespawnData[UserId] = {
["RespawnTime"] = RespawnTime,
["RespawnPoint"] = _RespawnPoint
}
return true
end
end,
}
for name, func in pairs(Exports) do
local Bf = Instance.new("BindableFunction")
Bf.Name = name
Bf.Parent = Folder
Bf.OnInvoke = function(args)
local success, err = pcall(func, args)
if not success then
warn("Export-"..name..": '"..err.."'")
end
end
end
_G.RespawnManager = Folder
local Players = game:GetService("Players")
if Players.CharacterAutoLoads == true then Players.CharacterAutoLoads = false end
Players.PlayerAdded:Connect(function(Player)
PlayerRespawnData[Player.UserId] = {
["RespawnTime"] = _RespawnTime,
["RespawnPoint"] = _RespawnPoint
}
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
wait(PlayerRespawnData[Player.UserId]["RespawnTime"])
if _CharacterAutoLoads then Player:LoadCharacter() end
end)
local HRP = Character:WaitForChild("HumanoidRootPart")
repeat
HRP.CFrame = PlayerRespawnData[Player.UserId]["RespawnPoint"]
wait()
until
((HRP.CFrame.Position - PlayerRespawnData[Player.UserId]["RespawnPoint"].Position).Magnitude < 10)
end)
if _CharacterAutoLoads then Player:LoadCharacter() end
end)
Players.PlayerRemoving:Connect(function(Player)
PlayerRespawnData[Player.UserId] = nil
end)
CustomRespawn.rbxl (26.5 KB)