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

Global function for both clients and server?

Asked by
Lolnox 47
6 years ago

I want to create a function which can be called by both clients and server and return some value but I'm kinda lost at this point, what I need to use in this case?

0
You can create a remoteEvent/Function and then call it from both server and client using either FireClient() from server or FireServer() from client. LegitmateTrades 159 — 6y

1 answer

Log in to vote
0
Answered by
farrizbb 465 Moderation Voter
6 years ago
Edited 6 years ago

What you're looking for is something called a module script.

What is a module script you may ask? Well a module script is a script that can be required - by the client and the server- and returns something back to the caller (this is normally a table).

For example:

--module

local module = {]


function module:KillCaller(Plr)
    Plr.Character.Humanoid.Health = 0
end

return module
--client
local KillKill = path.ModuleScript
local Player = game:GetService("Players").LocalPlayer

KillKill:KillerCaller(Player) -- will kill the client

Module scripts are the best option for the question and can be used in lots of ways:like datastores, 3d triangles and etc...

Module Scripts on the wiki

0
Oh, that's exactly what I was looking for! Thank you Lolnox 47 — 6y
Ad

Answer this question