我正在制作一个阶段选择器,您可以在我的 Roblox 游戏中前进和后退阶段, 但它不起作用,这是代码:
local trasferHandler = {}
local TOTAL_STAGES_IN_GAME = 10
for _, stage in pairs(workspace.Checkpoints:GetChildren()) do
if tonumber(stage.Name) > TOTAL_STAGES_IN_GAME then
TOTAL_STAGES_IN_GAME = tonumber(stage.Name)
end
end
function trasferHandler.up(plr, direction)
local tpStage = plr.TeleportedStage
if tpStage.Value < plr.leaderstats.Stage.Value then
tpStage.Value += 1
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.TeleportedStage.Value].CFrame + Vector3.new(0,3.25,0)
elseif tpStage.Value == plr.leaderstats.Stage.Value then
tpStage.Value = 0
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints["0"].CFrame + Vector3.new(0,3.25,0)
end
end
function trasferHandler.up2(plr, direction)
local tpStage = plr.TeleportedStage
if tpStage.Value < plr.leaderstats.Stage.Value then
tpStage.Value += 10
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.TeleportedStage.Value].CFrame + Vector3.new(0,3.25,0)
elseif tpStage.Value == plr.leaderstats.Stage.Value then
tpStage.Value = 0
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints["0"].CFrame + Vector3.new(0,3.25,0)
end
end
function trasferHandler.down2(plr, direction)
local tpStage = plr.TeleportedStage
if tpStage.Value > 10 then
tpStage.Value -= 10
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[tpStage.Value].CFrame + Vector3.new(0,3.25,0)
elseif tpStage.Value == 0 then
tpStage.Value = plr.leaderstats.Stage.Value
plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.leaderstats.Stage.Value].CFrame + Vector3.new(0,3.25,0)
end
end
return trasferHandler
我本以为它会改变我所处的阶段,但不知何故,它也打破了我倒退的能力。
local checkpoints=workspace.Checkpoints
local TOTAL_STAGES_IN_GAME=#checkpoints:children()
local function tp(player,x)
local val=Instance.new"DoubleConstrainedValue"
val.MaxValue=TOTAL_STAGES_IN_GAME-(checkpoints:FindFirstChild"0"and 1 or 0)
val.MinValue=checkpoints:FindFirstChild"0"and 0 or 1
local stage=player.leaderstats.Stage
val.Value=stage.Value
val.Value+=x
stage.Value=val.Value
local char=player.Character
char=char and char:move(checkpoints[stage.Value].Position)
--player.TeleportedStage=stage.Value
end
return {
up=function(player)
tp(player,1)
end,
up2=function(player)
tp(player,10)
end,
down2=function(player)
tp(player,-10)
end
}