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

2 comments
BindableEvents arent callbacks, so yielding shouldn't be a problem. Are you getting an error?
No, no errors in my console