I need to create a class or group of functions like:
function move(x, y, z) --body end function eat(food) --body end
and add this in the caracter (or what ever, I need this in the client), and call this functions from the client, but this has to be separate files.
Any help will be appreciated.
Well, what I'm getting at is that you need a module script or a RemoteEvent. I highly recommend a Remote Event.
Remove Event and Remote Function Tutorial
The difference between a Remote Event and Remote Function is that a Remote Function has a callback so you can return a value.
First up, you need to create a RemoteEvent. You should always put RemoteEvents and RemoteFunctions inside of ReplicatedStorage. I created one and called it 'Event'
Now, from what I'm getting at you want the functions inside of the Client and the functions to be called by the Server. Here's the Client script:
function move(x, y, z) -- body end function eat(food) -- body end game.ReplicatedStorage.Event.OnClientEvent:connect(function(request, func, ...) if request == "runFunction" then if func == "move" then args = {...} x = args[1] y = args[2] z = args[3] move(x, y, z) elseif func == "eat" then args = {...} food = args[1] eat(food) end end end)
When you use ... as an argument, it basically creates let's you pass infinite arguments after. If you do args = {...}
that turns all the arguments passed into a table. In your server script:
game.ReplicatedStorage.Event:FireClient("runFunction", "move", 5, 8, 10) -- Runs the function 'move' with x = 5, y = 8, and z = 10
or you can do this for eat:
game.ReplicatedStorage.Event:FireClient("runFunction", "eat", "apple") -- Runs the function 'eat' and passes 'apple'
Hope I helped! If you want to learn about ModuleScripts be sure to check this out:
If I did help out, please let me know :)