Can only FireClient from the server

I am creating a notification menu, and I want every notification that pops up also make a message in the chat. I am doing this using RemoteEvent:FireClient(), but the module is used on both the server AND client. Is there any way I could make this so that it still fires on the client? Any help would be greatly appreciated.

Here is the script:

local module = {}
local NotifyTemplate = script:WaitForChild("NotificationTemplate")	

function module:NotifyPlayer(player, text)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local NotificationsGui = PlayerGui.Main:WaitForChild("Popups")
	
	local newNotify = NotifyTemplate:Clone()
	newNotify.Text = text
	newNotify.Parent = NotificationsGui
	newNotify.BackgroundColor3 = Color3.fromRGB(34, 87, 168)
	
	
	
	local text_new_ = "[" .. text .. "]" 		

--HERE is the BUG: 
game.ReplicatedStorage.Otherremotes.ChatMakeSystemMesage:FireClient(player ,text_new_)
	
	newNotify:TweenSize(UDim2.new(0, 380,0, 28), Enum.EasingDirection.Out, Enum.EasingStyle.Back,0.15)
	coroutine.wrap(function()
		wait(3)
		for t = 0,1,0.1 do
			newNotify.BackgroundTransparency = t
			newNotify.TextTransparency = t
			wait()
		end
		wait(0.05)
		newNotify:Destroy()
	end)()
end

return module

I don’t believe you can ascertain the context in which a ModuleScript is being used to differentiate between server/local script, could you not just have a 2nd ModuleScript which is solely used in local scripts for the FireClient()/FireAllClients() calls?

I have seen a few ways to do this, but have managed to avoid using any of them so far. They mainly involve using either 2 events, or a variable defining where the function was called. Pull out the part of the function that is the same in both calls, then write 2 paths to execute it.

You can use the :IsServer() or :IsClient() function on RunService RunService | Roblox Creator Documentation

Just run your :FireClient function conditionally if :IsServer() returns false or :IsClient() returns true

2 Likes

You can try using BindableEvents. They fire from Client-Client or from Server-Server.