I want to exclude the use of a clunky spawn box / touched event respawning system in favor of simply using the CharacterAdded event, but my issue here is that the character doesn't teleport after the event is fired. I've put in a wait(1) as a temporary solution, but it's awkward when you float in space for a moment before being teleported. Using a bindable function here so other scripts can access this function. (On another note, I feel like this should be in server storage so players can't access it.)
local func = Instance.new('BindableFunction')
func.Name = 'TeleportToBase'
func.Parent = Workspace
function func.OnInvoke(char, base)
base = base or (Workspace:FindFirstChild('Map') or Workspace:FindFirstChild('Spawn')).Base
local width = base.Size.x/2 - 10
local length = base.Size.z/2 - 10
local height = base.Size.y / 2
char:MoveTo(base.Position + Vector3.new(math.random(-width, width), height + 10, math.random(-length, length)))
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
wait(1)
func:Invoke(char)
end)
end)
