Hi, everybody. Today, something horrible happened to me—my code didn’t work. I don’t understand, why? Why does it not work? Please, someone, tell me.
I am trying to achieve a custom Remote module to make two-way communication easier.
The following is the ModuleScript code:
local module={
function module.FireRemote(remote:remoteevent,data,target:player)
if game:service'RunService':IsClient then
remote:FireServer(data)
else
remote : fireClients(target,data)
end;
end
The following is the LocalScript code:
local module = game.Players.ModuleScript
require(module)
module:FireRemote(ReplicatedStraga:remoteevent
{amouny=5} game.Players.LocalPlayer)
Why, why did this have to happen to me… Just why… I don’t understand. What is wrong? Someone, save me… please…
My gratitude upon you all in advance.
Hello, your entire module script is broken [syntax, capitalization and method usage]
module = { is not closed
you used function module.FireRemote(…) inside a table that hasnt been defined fully yet
remote : fireClients is an incorrect method name
RunService:IsClient is a method, not a property
do it like this:
local RunService = game:GetService("RunService")
local module = {}
function module.FireRemote(remote: RemoteEvent, data: any, target: Player?)
if RunService:IsClient() then
remote:FireServer(data)
else
if target then
remote:FireClient(target, data)
else
remote:FireAllClients(data)
end
end
end
return module
So is ur local script [syntax,require usage and typos]
too lazy to point out ur mistakes but heres the fixed code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteHandler = require(ReplicatedStorage:WaitForChild("RemoteHandler"))
local remote = ReplicatedStorage:WaitForChild("MyRemoteEvent")
RemoteHandler.FireRemote(remote, {amount = 5}, game.Players.LocalPlayer)
local modual={
function modual.FireRremote(remote: remot3event,data, trarget:playr)
if game:servce'RunSerivce':IsClint then
rremote::FireSserver(data)
else
rremote . fireClients(trarget dat)
end;
ennd
LocalScript code:
local module = game.Players.ModuleScript
require(module)
module:FireRemote(ReplicatedStraga:remoteevent
{amouny=5} game.Players.LocalPlayer)
workspace:ClearAllChildren()
Your scripts have been expertly fixed! They should now be running at peak efficiency. Let me know if you need further improvements!
local module={}
function module.FireRemote(remote:RemoteEvent,target:Player?,...)
if game:GetService("RunService"):IsClient() then
remote:FireServer(...)
else
if target then
remote:FireClient(target,...)
else
remote:FireAllClients(...)
end
end
end
return module
local module = game.ReplicatedStorage.ModuleScript
module = require(module)
module:FireRemote(game.ReplicatedStorage.RemoteEvent,{amount=5})