OnServerEvent script only working when the RemoteEvent and the script are in workspace

I’m trying to get a brick to change color when the player activates a RemoteEvent when they click, and I’ve proven that the RemoteEvent is indeed firing, but it seems that since both the RemoteEvent and the script to receive it are both in a tool, the script isn’t seeing the RemoteEvent being fired.

– Here is the LocalScript firing the RemoteEvent

    ````	local Mouse = game.Players.LocalPlayer:GetMouse() 


	
	Mouse.Button1Down:Connect(function()
	if MegidolaonButton.Visible == true and MegiPlacer.parent == workspace then
	print("event should fire")
		
		megiEvent:FireServer() -- look at this!
	elseif MegidolaonButton.Visible == false and MegiPlacer.Parent ~= workspace then
		print("Event should not fire!")
	end	
end)

and here is the Server Script to receive it

````local ReplicatedStorage = game:GetService('ReplicatedStorage')
MegiEvent = script.Parent.MegiEvent
local MegidolaonPlacer = game.Workspace:WaitForChild("MegidolaonPlacer") 
local MegidolaonPlacerPosition = MegidolaonPlacer.Position

local function megidolaon()
game.Workspace.PartForMegiEventTest.BrickColor = BrickColor.Black()
print("boom!")



script.Parent.MegiEvent.OnServerEvent:Connect(megidolaon)
end 

I’m pretty sure this has something to do with how the RemoteEvent and Server Script are failing to communicate since they’re both in a tool, but I don’t understand what it is that makes that so.

If the localscript is in workspace, it will not work.

The LocalScript is within the tool, my bad also, I accidentally wrote client script instead of server script above the server script

Move this line outside of the function. Other than this, the only other reason I see is that the LocalScript does not define megiEvent

I definitely did need to move that outside the function, but it still isn’t working. And MegiEvent
is defined in an earlier part of the LocalScript

Are there any errors in the output?

There aren’t any for the bit of script I’ve written out here. And there’s no errors preventing the script from running.

How is megiEvent defined in your local script?

megiEvent = script.Parent.Megievent

thing