Keep in mind that I'm v e r y new to scripting in Lua. I'm trying to make an obby, and I want the player to spawn at a certain checkpoint depending on the stage they are on once they fail.
Here's what I thought would work, and I'm uncertain if there's a way to do this.
game.Workspace.Model[leaderstats.Stage.Value]
Basically, I have each checkpoint grouped as a model with their names as "2","3","4", etc...
Pretend I'm on stage 2, and I fail. I have the player teleported to the stage's checkpoint (which is determined by the name of the Checkpoint in their own groups/models).
How can I achieve that?
Full Script (Located in ServerScriptStorage):
function repsawn(object)
local player = game.Players:GetPlayerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local checkpoint = game.Workspace.Model[ls.Stage.Value]
object.HumanoidRootPart.CFrame = object.HumanoidRootPart.CFrame + Vector3.new(0,3,0)
wait()
object.HumanoidRootPart.CFrame = checkpoint.CFrame + Vector3.new(0,3,0)
end
end
game.Workspace.ChildAdded:connect(repsawn)
If I missed any info probably did, then please tell me! :D
