简体   繁体   English

BindableEvent 未触发 Lua

[英]BindableEvent Not Firing Lua

I have a BindableEvent within the ReplicatedStorage in a folder for events, being called from a script in a part, that does not seem to be firing, what could be going wrong?我在事件文件夹中的 ReplicatedStorage 中有一个 BindableEvent,从部分脚本调用,似乎没有触发,可能出了什么问题?

Code: Sender(In part):代码:发件人(部分):

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

Receiver(In folder):接收者(在文件夹中):

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)

Thanks for the help!谢谢您的帮助!

It looks like you've put the Receiver Script in ReplicatedStorage as well, and that isn't one of the locations that Scripts execute.看起来您也将接收器脚本放在了 ReplicatedStorage 中,这不是脚本执行的位置之一。 According to the documentation :根据 文档

The instant that the following conditions are met, a Script's Lua code is run in a new thread:满足以下条件的瞬间,脚本的 Lua 代码在新线程中运行:

  • Disabled property is false禁用属性为假
  • The Script object is a descendant of the Workspace or ServerScriptService脚本 object 是 Workspace 或 ServerScriptService 的后代

So your BindableEvent is probably firing correctly, but the Script you have to listen for the event is never running, so it is never connecting to the event.因此,您的 BindableEvent 可能正确触发,但是您必须侦听该事件的脚本从未运行,因此它永远不会连接到该事件。 Try moving the Script into the Workspace or ServerScriptService and update the path to the Event.尝试将脚本移入 Workspace 或 ServerScriptService 并更新事件的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM