当玩家触摸该部分时,舞台价值不会增加

问题描述 投票:0回答:1

所以这是在 roblox 工作室所以呃..我有点新所以...我不知道如何解决这个问题这是代码。
我会解释一下代码,呃..
玩家应该触摸工作区中的检查点。检查点
当他们触摸这些时,Stage.Value 应添加 + 1
然后当他们达到 30 岁时,他们会触摸一个可以让他们进入获胜者排行榜的部分
这也会加起来..所以呃

似乎什么也没发生,控制台中也没有发现任何错误

local Checkpoints = workspace.Checkpoints

game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"
    local Stage = Instance.new("IntValue", leaderstats)
    Stage.Name = "Stage"
    Stage.Value = nil

    local Wins = Instance.new("IntValue")
    local WinnerArea = workspace.Checkpoints.WinSpawn
    Wins.Name = "Wins"
    Wins.Parent = leaderstats
    Wins.Value = 0

    WinnerArea.Touched:Connect(function(hit)
        if tonumber(Stage.Value) == 30 then
            Wins.Value = Wins.Value + 1
            Stage.Value = 0
        end
    end)

    local lastCheckpointName = ""  -- Store the name of the last touched checkpoint

    for _, checkpoint in pairs(Checkpoints:GetChildren()) do
        checkpoint.Touched:Connect(function(hit)

            if hit.Parent:FindFirstChild("Humanoid") then
                local char = hit.Parent

                -- Ensure the player is the owner of the character
                if char.Parent == plr.Character then

                    if tonumber(checkpoint.Name) == Stage.Value then
                        lastCheckpointName = checkpoint.Name  -- Store the name of the last touched checkpoint
                        Stage.Value = Stage.Value + 1
                        
                        
                    elseif checkpoint.Name == "MainObbySpawn" then
                        Stage.Value = 0

                        lastCheckpointName = checkpoint.Name  -- Store the name of the last touched checkpoint
                    end
                end
            end
        end)
    end

    plr.CharacterAdded:Connect(function(char)
        wait()
        local checkpointToMoveTo = Checkpoints:FindFirstChild(lastCheckpointName)
        if checkpointToMoveTo then
            
            char:MoveTo(checkpointToMoveTo.Position)
        elseif Checkpoints:FindFirstChild("MainObbySpawn") then
            char:MoveTo(Checkpoints:FindFirstChild("MainObbySpawn").Position)
        end
    end)
end)

所以我尝试修复一些变量并依赖ai哈哈...没有任何反应,即使控制台没有显示任何相关错误

lua roblox
1个回答
0
投票

您的代码的问题是您试图查看

Workspace
是否为
plr.Character
。你制作
char = hit.Parent
然后检查是否
char.Parent == plr.Character
本质上检查是否
hit.Parent.Parent == plr.Charcter
, 但它不会。

我希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.