如何让这段代码正确运行?

我想在 Roblox Studio 中制作一种大厅系统,当你在一个部分有4个人时,你会被送到另一个地方。我尝试了设置一个系统,但它没有起作用; 你能帮我解决这个问题吗?

我试图让它在结尾处说.Value。

local TeleportService = game:GetService("TeleportService")

player_amount = script.Parent.Parent.Parent.Player_Count
local placeID_1 = 4119652438
local function onPartTouch(otherPart)
    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
    if player then
        player_amount.Value = player_amount.Value + 1
    end
    if player_amount == 4 then
        TeleportService:Teleport(placeID_1, player)
    end
end

script.Parent.Touched:Connect(onPartTouch)

我期望的输出应该是 0,然后如果有一个人踩上它,它会更新标志以显示 1。但它只停留在 0。

点赞
用户8897797
用户8897797

这不是一个可行的解决方案,因为 .Touched 每帧都会在玩家触碰到一个部件时触发,并且只有在他们移动时才触发。我建议创建一个碰撞框,就像我在这里所做的一样(https://devforum.roblox.com/t/detecting-on-which-map-the-character-is/233463/13)

2019-11-09 22:32:30