BindableEvent 未触发 Lua

BindableEvent Not Firing Lua

我在事件文件夹中的 ReplicatedStorage 中有一个 BindableEvent,它是从某个部分的脚本调用的,它似乎没有触发,可能出了什么问题?

代码: 发件人(部分):

local popEvent = game.ReplicatedStorage.Events.PopEvent

local lvl = script.Parent.Parent:GetAttribute("Level")
local pops = game.Workspace.PopParts
local lvlPop = pops:FindFirstChild("Lvl"..tostring(lvl))
local kids = lvlPop:GetChildren()

while true do
    for i, v in pairs(kids) do
        popEvent:Fire(script.Parent, v)
        print("here")
    end
    wait(3)
end

收件人(在文件夹中):

script.Parent.Event:Connect(function (pt1, pt2)
    print("there")
    if (pt1:IsA("Part") and pt2:IsA("Part")) then
        local x1 = pt1.Position.X
        local l1 = pt1.Size.X / 2
        local x2 = pt2.Position.X
        local l2 = pt2.Size.X / 2
        
        local z1 = pt1.Position.Z
        local d1 = pt1.Size.Z / 2
        local z2 = pt2.Position.Z
        local d2 = pt2.Size.Z / 2
        
        if ((x1 + l1 < x2 - l2 and x1 - l1 > x2 + l2) and (z1 + d1 < z2 - d2 and z1 - d1 > z2 + d2)) then
            pt1.Transparency = 1
            pt1.Anchored = false
        end
    else
        if not(pt1:IsA("Part")) then
            warn("pt1 isn't a part")
        elseif not(pt2:IsA("Part")) then
            warn("pt2 isn't a part")
        end
    end
end)

感谢您的帮助!

您似乎也将 Receiver Script 放在了 ReplicatedStorage 中,而那不是脚本执行的位置之一。根据 the documentation :

The instant that the following conditions are met, a Script’s Lua code is run in a new thread:

  • Disabled property is false
  • The Script object is a descendant of the Workspace or ServerScriptService

因此您的 BindableEvent 可能正确触发,但您必须侦听事件的脚本永远不会 运行,因此它永远不会连接到事件。尝试将脚本移动到工作区或 ServerScriptService 并更新事件的路径。