Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why do remote functions not work in ModuleScripts?

Asked by 6 years ago
Edited 6 years ago
local hlFunc = game:GetService("ReplicatedStorage").Remotes:WaitForChild("hlFunc"):InvokeClient(player)

    return hlFunc

This is inside a normal function inside of a modulescript and it says i cant use InvokeClient() on the server, and then when i put in InvokeServer its vice versa.

2 answers

Log in to vote
1
Answered by 6 years ago

When you are using a ModuleScript, the module will be ran by the type of script that you require it with. So say you ran

--/Server Script
local hlFunc = require(game:GetService("ServerStorage"):FindFirstChild("ModuleScript"));

That would allow you to run it as a Server Script and allow the ModuleScript to run InvokeClient(), whereas requiring it from a LocalScript will run it as a LocalScript from whichever player's client the script is on (All of them unless you only put it in a certain player)

--/Local Script
local hlFunc = require(game:GetService("ServerStorage"):FindFirstChild("ModuleScript"));

Requiring it in the LocalScript would error because you cannot run InvokeClient() from a client.

If this help, that's awesome! If it didn't and you're still confused feel free to ask any other questions to have about it, or ask me to clarify what confused you.

0
this kinda helped i had a little slip up in my code randomly cause i accidentally coppied some code and still had an invokeclient() in there even tho its client tho, but i am still accepting this as it teeached me a bit of module scripts, thaanks HilyrHere 79 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Well, because remote events can't be invoked as they aren't remote functions, but they can be fired with the FireServer(), FireClient, and FireAllClients() functions. Then they can be recieved by other scripts or local scripts with the OnServerEvent(), and OnClientEvent events. Ex:

--local script
local re = game.ReplicatedStorage.RemoteEvent
re:FireServer("ding")
--server script
local re = game.ReplicatedStorage.RemoteEvent
re.OnServerEvent:Connect(function(plr,thing)
    print(plr.Name,thing)
end)

I think what you are trying to do the invoke a remote function and doing that looks something like:

--local script
local rf = game.ReplicatedStorage.RemoteFunction
local ding = rf:InvokeServer("Dab")
print(ding)--3
--server script
local rf = game.ReplicatedStorage.RemoteFunction
rf.OnServerInvoke = function (plr,thing)
    return #thing
end
0
i meant remote fuctions not events oops HilyrHere 79 — 6y

Answer this question