Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

why is my BindableEvent unexpectedly yielding?

Asked by 3 years ago

i'm working on a cutscene module, and have a fade script setup which connects to two client-sided BindableEvents, which it responds to by either fading in or fading out. in my cutscene module i have a function for both of these that fires their respective event. but during my tests where i tried to move the player's camera, the camera shift happened the instant the fade started, so then i set up a "fade completed" event and tried doing a :Wait on it, but it had no change. i tried printing, and narrowed the cause down to something to do with the bindableevents but couldn't figure out what, so i tried hardcoding in a wait as a last resort. however, i found that what occured was that the bindableevent also yielded, despite there being no waits or yields within the connection to it, and there are no other functions that yield before firing it, and this appears to be the root of the problem, since if the bindableevent didn't yield this would work just fine

fadein/fadeout code

local LP = game:GetService("Players").LocalPlayer
local FADE_IN = LP.PlayerScripts.Events.GUI:WaitForChild("FADE_IN")
local FADE_OUT = LP.PlayerScripts.Events.GUI:WaitForChild("FADE_OUT")
local FADE_GUI = LP.PlayerGui:WaitForChild("Effects"):WaitForChild("Fade")

local function fadein(time)
    local fadeIn = TweenService:Create(FADE_GUI, TweenInfo.new(time), {
        BackgroundTransparency=0
    })

    fadeIn:Play()
    fadeIn.Completed:Wait() --this shouldn't matter since bindableevents should be running in separate lua threads, and the tween starts playing immediately anyways, so this _should_ fire, immediately play, then the wait in the script below gives it enough time to fade completely, but instead the tween just doesn't play until the wait finishes
end

local function fadeout(time)
    local fadeOut = TweenService:Create(FADE_GUI, TweenInfo.new(time), {
        BackgroundTransparency=1
    })

    fadeOut:Play()
    fadeOut.Completed:Wait()
end

FADE_IN.Event:Connect(fadein)
FADE_OUT.Event:Connect(fadeout)

function in moduleScript that fires the events

function module:FadeIn(t: number)
self.PlayerActor.Player.PlayerScripts:WaitForChild("Events")
:WaitForChild("GUI"):WaitForChild("FADE_IN"):Fire(t)
    --playeractor is just a cloned model of the player i use for animating and also points to a player object, there's no issue finding the bindable, just it being weird with yielding
    wait(t * 2) --the hardcoded wait i tried
    return self
end

function module:FadeOut(t: number)
self.PlayerActor.Player.PlayerScripts:WaitForChild("Events")
:WaitForChild("GUI"):WaitForChild("FADE_OUT"):Fire(t)
    wait(t * 2)
    return self
end

function in modulescript that calls the functions

function module:Launch(cutscene: ModuleScript)
    self.Camera.CameraType = Enum.CameraType.Scriptable
    local csd = require(cutscene)
    local plr = self.PlayerActor.Player

    if csd.Init then
        csd:Init(self, plr)
    end
    self:FadeOut(csd.FadeOutTime)
    if csd.Pre then
        csd:Pre(self, plr)
    end

    self:FadeIn(csd.FadeOutTime)
    csd:Play(self, plr)
    self:FadeOut(csd.FadeOutTime)
    if csd.End then
        csd:End(self, plr)  
    end
    self.Camera.CameraType = Enum.CameraType.Custom
    self:FadeIn(csd.FadeInTime)
    return self
end

cutscene module

local cutscene = {}
cutscene.FadeOutTime = 0.5
cutscene.FadeInTime = 0.5
function cutscene:Pre(director)
    director:SetCamera(workspace:WaitForChild("Part").CFrame) --the camera movement doesn't yield and works fine
end

function cutscene:Play(director)
    director:MoveCamera(workspace:WaitForChild("Part2").CFrame)
end
return cutscene

script that fires :Launch

local RS = game:GetService("ReplicatedStorage")
local REMOTE_LAUNCH_CUTSCENE = RS:WaitForChild("Events")
:WaitForChild("Cutscene")
:WaitForChild("LAUNCH_CUTSCENE")

REMOTE_LAUNCH_CUTSCENE.OnClientEvent:Connect(function(cutscene)
    local data = RS:WaitForChild("Cutscenes"):FindFirstChild(cutscene)
    if not data then warn("no cutscene module for", cutscene) return end

    director:Launch(data)
end)

the test script that fires the cutscene event (server-sided)

wait(5)
game.ReplicatedStorage.Events.Cutscene.LAUNCH_CUTSCENE
:FireClient(game:GetService("Players"):GetPlayers()[1], "TestCutscene")--"TestCutscene" is the name of the cutscene module, which it has no trouble finding

i have tried

  • making sure the correct functions are being called, which they are
  • making sure the values of arguments passed to the fade functions is correct, which they are
  • connecting print statements to the bindable events, which is how i discovered this
  • putting prints before and after firing the events to see the codeflow, which is as expected

i'm extremely confused, as to my knowledge bindableevents run in separate lua threads, so if i wait in another script, that shouldn't delay when the effects of the bindable happen

0
BindableEvents arent callbacks, so yielding shouldn't be a problem. Are you getting an error? Benbebop 1049 — 3y
0
No, no errors in my console BrimoireGrimoire 11 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

A Bindable Event Needs To Be A Array That's Not A Mixture., If A Table Is Passed To A Argument. If It Yielding Should'nt Be A Problem.

0
data loss isn't the problem, all the information is sending just fine, it's just that the effects of the bindableevent are delaying despite there being no waits/yields in it's connection or before i fire it, i only do a wait _after_ firing it BrimoireGrimoire 11 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I managed to find a solution, and it was just to forgo the use of bindableevents entirely and make the fade part of the module directly

still have no idea why that delay was happening though, odd

Answer this question