在 Roblox Studio 上编写脚本

问题描述 投票: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)

我的按钮不起作用,我认为这里有错误,如果您可以在 roblox studio 中提供帮助,请回复您的用户,我添加您

lua roblox
1个回答
0
投票

我假设您希望该按钮在单击时激活,但我看到 .Touched:Connect。这可以检测该部件何时被另一个物体触摸/撞击。要检测点击,您需要有一个点击检测器元素作为按钮部分的子元素。然后将脚本内的点击检测器定义为

local clickDetector = script.Parent.ClickDetector
。不要使用
ButtonPart.Touched:Connect
,而是尝试使用
clickDetector.MouseClick:Connect

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