Roblox 如何修复 If 语句?

我正在为我的游戏开发一种武器,但是我遇到了一些问题。这个武器不是一个工具,而是连接到一个起始角色。我编写了以下脚本来检查武器是否被装备,然后允许玩家攻击。

Mouse.Button1Down:connect(function()
    if isEquipped == true then
        if not pause then
            pause = true
            anim1:Play()
            wait(0.1)
            trail.Enabled = true
            wait(0.6)
            trail.Enabled = false
            pause = false
        end
    end
end)

handle.Touched:connect(function(hit)
    if isEquipped == true then
        if not pause2 then
            pause2 = true
            if Mouse.Button1Down then
                if humanoid and humanoid.Health > 0 and hit and not hit:isDescendantOf(person) then
                    local target = hit.Parent:FindFirstChild("Humanoid")
                    if target and target.Health > 0 then
                        target:TakeDamage(damage)
                        wait(0.7)
                        pause2 = false
                    end
                end
            end
        end
    end
end)

game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(KeyPressed)
        if KeyPressed == "e" then
            if not pause3 then
                pause3 = true
                if toggle == false then
                    toggle = true
                    isEquipped.Value = true
                    fake1.Transparency = 1
                    fake2.Transparency = 1
                    disc1.Transparency = 0
                    disc2.Transparency = 0
                    wait(0.7)
                    pause3 = false
                else
                    pause3 = true
                    toggle = false
                    isEquipped.Value = false
                    fake1.Transparency = 0
                    fake2.Transparency = 0
                    disc1.Transparency = 1
                    disc2.Transparency = 1
                    wait(0.7)
                    pause3 = false
            end
        end
    end
end)

问题是我能够装备这个武器,但是当它被装备时,我不能使用它攻击。感谢您提前的帮助!

点赞
用户88888888
用户88888888

在你提供的代码中,没有一个部分实际上将 isEquipped 设为 true。你应该将这个值绑定到 tool.Equipped 事件上。

如果你想了解更多信息,我建议你访问 Roblox Wiki。

此外,你使用的是 LocalScript 还是 Script?如果你使用的是 LocalScript,针对影响其他客户端的事情(例如声音、设置部件属性、创建部件等等)应该使用 RemoteEvents。您可以在 Roblox Wiki 中找到有关此客户端-服务器通信模型的更详细信息。

另外,在程序开始时,pause3 的值是什么?你给这个变量赋了什么值?它应该被设置为 false,否则你将无法进行攻击。

2018-11-28 00:46:56