代码之家  ›  专栏  ›  技术社区  ›  Gamerboi677 _YT

如果玩家触摸了某个部分,如何将玩家名称添加到数组中。-Roblox-Lua编码

  •  0
  • Gamerboi677 _YT  · 技术社区  · 1 年前

    我最近遇到了麻烦,当我试图在一个数组中添加一个玩家时,如果一个部分被触摸了,但我似乎无法使其工作。

    这是我的代码:

                    playerWin = {}
    
            game.Workspace.SharkSurvival.givewin.Touched:Connect(function(TouchedPart)
                if TouchedPart.Parent:FindFirstChild("Humanoid") then
                    local Character = TouchedPart.Parent
                    local Player = game.Players:GetPlayerFromCharacter(Character)
                    local AlreadyInTable = false
                    -- Now make sure the player isn't already in the array
                    for _,OtherPlayer in next,playerWin do
                        if OtherPlayer == Player then
                            AlreadyInTable = true
                        end
                    end
                    if not AlreadyInTable then
                        -- Add them to the array!
                        table.insert(playerWin,Player.Name)
                    end
                end
            end)
    

    任何帮助都将不胜感激。 谢谢

    我希望我数组中的第一个对象是触摸该部分的玩家。

    0 回复  |  直到 1 年前