LocalScript doesn't receive bindable event fire, but the whole script runs (HELP)

I have a loading screen, that loading screen fires a bindable event that a local script receives
when that local script receives the event, it’s supposed to do cool things, but it’s not even receiving the fire

very weird?
script that fires:

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local contentProvider = game:GetService("ContentProvider")
local rStorage = game:GetService("ReplicatedStorage")
local tService = game:GetService("TweenService")
local tweenParameters = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out
)

-- Path to events;
local events = rStorage:WaitForChild("Events")
local fromClient = events:WaitForChild("FromClient")
local functionalityEvents = fromClient:WaitForChild("Functionality")
local bindableEvents = events:WaitForChild("Bindable")

-- Events;
local menuOnLoad = bindableEvents:WaitForChild("MenuOnLoad")
local loadCharacter = functionalityEvents:WaitForChild("LoadCharacter")

-- Player variables;
local plr = game:GetService("Players").LocalPlayer
plr.CameraMode = Enum.CameraMode.LockFirstPerson
local plrGui = plr.PlayerGui

-- Cloned instances and assets to load;
local ui = script:WaitForChild("LoadingScreen"):Clone()
local assets = game:GetDescendants()
ui.Parent = plrGui

-- Gui elements;
local quotes = ui:WaitForChild("Quotes")
local frame = ui:WaitForChild("Frame")
local icon = ui:WaitForChild("Icon")

-- Tables;
local quoteChances = {
	["The dead scream louder in silence."] = 10,
	["Monsters aren’t born—they’re remembered."] = 10,
	["Every corpse hides a lost story."] = 10,
	["The dead rose when humanity fell."] = 10,
	["We fear them because they were us."] = 9,
	["Survival means stepping over loved ones."] = 10,
	["They were us; we’ll be them."] = 10,
	["The apocalypse reveals hollow souls."] = 10,
	["The living haunt the dead, not the other way."] = 10,
	["Hope dies faster than flesh."] = 10,
	["Peepee Poopoo."] = 1
}

-- Functions;
local function SelectQuote()
	local totalChance = 0
	for _,chance in pairs(quoteChances) do
		totalChance += chance
	end

	local rng = math.random(1,totalChance)

	for quote, chance in pairs(quoteChances) do
		rng -= chance
		if rng <= 0 then
			return quote
		end
	end
end

local function CycleQuotesWhileLoading()
	while not game:IsLoaded() do
		quotes.Text = SelectQuote()
		task.wait(5)
	end
end

local function LoadGame()
	task.spawn(CycleQuotesWhileLoading)
	
	-- preload while game isn't loaded
	while not game:IsLoaded() do
		local success, result = pcall(function()
			contentProvider:PreloadAsync(assets)
		end)

		if not success then
			warn("Failed to load asset: " .. result)
		end
	end
	
	warn("Assets loaded!")
	
	-- once loaded, tween everything
	local frameTween = tService:Create(frame, tweenParameters, {BackgroundTransparency = 1})
	local iconTween =tService:Create(icon, tweenParameters, {ImageTransparency = 1})
	local quotesTween = tService:Create(quotes, tweenParameters, {TextTransparency = 1})

	frameTween:Play()
	iconTween:Play()
	quotesTween:Play()
	
	-- fire events
	menuOnLoad:Fire()
	warn("yes i have fired")
	loadCharacter:FireServer()
	
	-- enable the main menu
	plrGui:WaitForChild("Menu").Enabled = true
	
	-- wait for tween to complete, destroy the ui and enable core gui elements
	frameTween.Completed:Wait()
	
	ui:Destroy()
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end

local function Setup()
	quotes.Text = SelectQuote()
	LoadGame()
end

-- Runtime;
Setup()

script that receives:

local rService = game:GetService("RunService")
local lService = game:GetService("Lighting")
local rStorage = game:GetService("ReplicatedStorage")
local tService = game:GetService("TweenService")
local players = game:GetService("Players")

-- Lighting elements;
local blur = lService:WaitForChild("Blur")
local atmosphere = lService:WaitForChild("Atmosphere")

-- Path to events;
local eventsFolder = rStorage:WaitForChild("Events")
local bindableEvents = eventsFolder:WaitForChild("Bindable")
local fromClient = eventsFolder:WaitForChild("FromClient")
local functionalityEvents = fromClient:WaitForChild("Functionality")

-- Events;
local menuOnLoad = bindableEvents:WaitForChild("MenuOnLoad")
local joinOrLeaveMatch = functionalityEvents:WaitForChild("JoinOrLeaveMatch")

-- Player variables;
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
local camera = workspace.CurrentCamera

-- Gui elements;
local menuGui = script.Parent
local mainFrame = menuGui:WaitForChild("MainFrame")

local buttonInfoFrame = mainFrame:WaitForChild("ButtonInfoFrame")
local infoLabel = buttonInfoFrame:WaitForChild("Info")

local quotesFrame = mainFrame:WaitForChild("QuotesFrame")
local quoteLabel = quotesFrame:WaitForChild("Quotes")

local mainButtonsFrame = mainFrame:WaitForChild("MainButtonsFrame")

local effectFramesFolder = menuGui:WaitForChild("EffectFrames")
local soundsFolder = menuGui:WaitForChild("Sounds")

-- Effect frames;
local blinkFrame = effectFramesFolder:WaitForChild("Blink")
local vignetteFrame = effectFramesFolder:WaitForChild("Vignette")

-- Sounds;
local buttonHoverSound = soundsFolder:WaitForChild("ButtonHoverSound")
local menuMusicSound = soundsFolder:WaitForChild("BGMusic")

-- Menu room;
local menuRoom = workspace:WaitForChild("MenuRoom", 1) or rStorage:WaitForChild("MenuRoom", 1)
local menuCameraParts: Model = menuRoom:WaitForChild("CameraParts")

-- Values;
local cameraSwayFrequency = 2
local cameraSwayAmplitude = 0.1

-- Tables;
local quoteArray = {
	"They're the shadow you can't outrun.",
	"Fear the quiet ones; they hear everything.",
	"In the dark, we're all the same prey.",
	"They warned you to not look back.",
	"The monsters never left; they just changed faces.",
	"It's not death you should fear, but what follows.",
	"I was never here, and yet, you'll never forget me.",
	"Silence speaks the loudest before the scream.",
	"Your fear is their playground.",
	"They're the nightmare you can't wake up from.",
	"The light won't save you, it only shows them where you are.",
	"Every breath you take is borrowed time",
	"You're not alone in the dark, you just wish you were.",
	"Don't worry, the worst is yet to come.",
	"The dead don't rest, and neither will you.",
	"There's a thin line between sanity and the abyss, you're about to cross it.",
	"When the shadows move, it's already too late.",
	"You'll never know the last moment you were safe.",
	"Your fate is already written, just in the dark.",
	"They come alive when the lights go out.",
}

local buttonInfoDictionary = {
	PlayButton = "Play the game.",
	ClassesButton = "Pick one that fits you.",
	TraitsButton = "Decide who you are.",
	ShopButton = "Customize your looks.",
	SanctumButton = "<s>Coming soon.</s>",
	SettingsButton = "Alter your experience."
}

-- Functions;

-- cycles quotes in quoteLabel while the menu UI is active
local function CycleQuotes()
	while menuGui.Enabled do
		local randomIndex = math.random(1, #quoteArray)
		local quote = quoteArray[randomIndex]

		quoteLabel.Text = quote
		task.wait(6)
	end	
end

-- alters camera and lighting for a better experience
-- runs whenever the player loads into the game (menuOnLoad gets received)
local function OnPlayerLoaded()
	print("Ass")
	-- set camera mode to third person to allow mouse movement
	-- but set min and max zoom distance to 8 to avoid absurd things
	plr.CameraMode = Enum.CameraMode.Classic
	plr.CameraMaxZoomDistance = 8
	plr.CameraMinZoomDistance = 8
	
	-- alter lighting
	blur.Enabled = true
	blur.Size = 9

	atmosphere.Density = 0.7
	atmosphere.Offset = 0
	
	-- play menu music
	menuMusicSound:Play()
	
	-- get main camera part
	local mainCameraPart = menuCameraParts:FindFirstChild("Main")
	
	-- if it doesn't exist, warn and return
	if not mainCameraPart then
		warn("Main camera part wasn't found!")
		return
	end

	-- bind the camera
	rService:BindToRenderStep("BindMenuCamera", Enum.RenderPriority.Camera.Value, function()	
		-- calculate offset
		local offset = math.sin(tick() * cameraSwayFrequency) * cameraSwayAmplitude
		
		-- set camera cframe
		camera.CFrame = mainCameraPart.CFrame + Vector3.new(offset, 0, 0)
	end)
end

-- sets up hover and activated connections for all the buttons that are visible on the main gui
local function SetupConnections()
	for _, button: ImageButton in mainButtonsFrame:GetChildren() do
		if not button:IsA("ImageButton") then continue end
		
		-- on button hovered
		button.MouseEnter:Connect(function()
			-- play the sound
			buttonHoverSound:Play()

			-- setup tween parameters and goal
			local labelTweenParams = TweenInfo.new(
				0.3,
				Enum.EasingStyle.Linear,
				Enum.EasingDirection.Out
			)

			local labelTweenGoal = {Position = UDim2.fromScale(0, 0)}

			-- create the tween
			local labelTween = tService:Create(infoLabel, labelTweenParams, labelTweenGoal)

			-- set the text color of the hovered button to black to allow readability
			local buttonTextLabel = button:FindFirstChildOfClass("TextLabel")

			-- if there is no text label, warn, return
			if not buttonTextLabel then
				warn("Unable to find a TextLabel in " .. button.Name)
				return
			end

			buttonTextLabel.TextColor3 = Color3.fromRGB(0,0,0)

			-- play label tween
			labelTween:Play()

			-- destroy the tween once it's completed
			labelTween.Completed:Once(function()
				labelTween:Destroy()
			end)
		end)
		
		-- on button hover ended
		button.MouseLeave:Connect(function()
			infoLabel.Position = UDim2.fromScale(-0.137, 0)

			-- get text label
			local buttonTextLabel = button:FindFirstChildOfClass("TextLabel")

			-- if no text label, warn, return
			if not buttonTextLabel then
				warn("Unable to find a TextLabel in " .. button.Name)
				return
			end

			-- reset text color
			buttonTextLabel.TextColor3 = Color3.fromRGB(255,255,255)
		end)
		
		-- on button activated
		button.Activated:Connect(function()
			-- activate blink effect
			blinkFrame.Visible = true
			
			-- create fade out tween
			local fadeOutTweenParams = TweenInfo.new(
				0.6,
				Enum.EasingStyle.Linear,
				Enum.EasingDirection.Out
			)
			
			local fadeOutGoal = {BackgroundTransparency = 1}
			local fadeOutTween = tService:Create(blinkFrame, fadeOutTweenParams, fadeOutGoal)
			
			-- play the tween
			fadeOutTween:Play()
			
			-- setup a :Once() to destroy it once it finishes
			fadeOutTween.Completed:Once(function()
				blinkFrame.BackgroundTransparency = 0
				blinkFrame.Visible = false
				fadeOutTween:Destroy()
			end)
			
			-- get the name of the button and remove "Button" from it			
			local buttonName = button.Name
			local splitButtonName = string.split(buttonName, "Button")
			local updatedName = splitButtonName[1]
			
			-- find the camera part to use inside the menu room
			local cameraPart: BasePart = menuCameraParts:FindFirstChild(updatedName)
			
			-- if no camera is found, warn, return
			if not cameraPart then
				warn("No camera part with the name " .. updatedName .. " was found in the menu room!")
				return
			end
			
			-- unbind menu camera and rebind it to the new part
			rService:UnbindFromRenderStep("BindMenuCamera")
			rService:BindToRenderStep("Bind" .. updatedName .. "Camera", Enum.RenderPriority.Camera.Value, function()
				-- calculate offset
				local offset = math.sin(tick() * cameraSwayFrequency) * cameraSwayAmplitude
				
				-- apply cframe
				camera.CFrame = cameraPart.CFrame * CFrame.new(offset, 0, 0)
			end)
		end)
	end
end

-- Runtime;
menuOnLoad.Event:Connect(OnPlayerLoaded)
SetupConnections()
print("am i even running??")

YES, the prints run (except for the one inside the OnPlayerJoined function

1 Like

No idea if this works but try use A RemoteEvent (i dont check the differents between the events)

Maybe try doing this instead

menuOnLoad.Event:Connect(function()
OnPlayerLoaded()
end)
1 Like

BindableEvent should work as long as these are both LocalScripts which it looks like.
RemoteEvent would not work.
Is the “am i even running” print before the warn(“yes i have fired”) ?
I’m wondering if the receiving LocalScript does not start listening until after it’s already been fired.

image

it’s really weird lol

Ok, so that’s the issue.
The event is firing before that other script is loaded and runs in order to listen to the event.

oopsies…

thanks for that debug cause i legit didn’t notice that, evne whne i sent that screenshot
#blind

i fixed it now

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.