So, I’m making a checkpoint system for my game, but there’s a problem that’s been bugging me: The player simply keeps spawning at the world’s SpawnLocation instead of being moved automatically when the character is loaded.
The script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local currentCheckpoint = ReplicatedStorage:WaitForChild("CurrentCheckpoint")
local module = {}
function module.loadCharacter(player)
player:LoadCharacter()
return player.CharacterAdded:Wait()
end
function module.loadAllCharacters()
for _, player in ipairs(Players:GetPlayers()) do
player:LoadCharacter()
end
end
function module.spawnCharacter(player, destinationCFrame)
local char = module.loadCharacter(player)
if destinationCFrame then
char:PivotTo(destinationCFrame)
elseif currentCheckpoint.Value and currentCheckpoint.Value:IsA("BasePart") then
local spawnPosition = currentCheckpoint.Value.CFrame * CFrame.new(0, 3.5, 0)
char:PivotTo(spawnPosition)
end
return char
end
return module
The part where I think the error is:
function module.spawnCharacter(player, destinationCFrame)
local char = module.loadCharacter(player)
if destinationCFrame then
char:PivotTo(destinationCFrame)
elseif currentCheckpoint.Value and currentCheckpoint.Value:IsA("BasePart") then
local spawnPosition = currentCheckpoint.Value.CFrame * CFrame.new(0, 3.5, 0)
char:PivotTo(spawnPosition)
end
return char
end
Video:
Thank for all helping!