在 Roblox 上编写脚本 - 我的按钮不起作用

问题描述 投票:0回答:1
v.ButtonPart.Touched:Connect(function(Hit)
        if Hit:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
            if Values.OwnerValue.Value == player then
                if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
                    if player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
                        player.leaderstats.Cash.Value -= v.Price.Value
                        items[v.items.Value].Parent = Boughtitems
                    end
                end
            end
        end
    end)

我的按钮不起作用。

lua roblox
1个回答
0
投票

我认为这不起作用的原因是因为这行:

 Hit:FindFirstChild("Humanoid")
。当您使用
.Touched:Connect(function())
时,函数的第一个参数是触及它的任何内容,因此如果您走过它,它将返回“LeftLeg”或类似的内容。你想要做的是在触及它的任何部分找到“Humanoid”,这绝对行不通。尝试将
if Hit:FindFirstChild("Humanoid") then
替换为
if Hit.Parent:FindFirstChild("Humanoid") then

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