You can’t call a server-side function from the client like this. Also, I think the function’s name should be LBCore.Functions.GetPlayers not LBCore.Functions:GetPlayers ?
Ok so I did that. I made a sh_main.lua file that is my shared, I put print(LBCore.Functions.Test()) there and it did not work. It gave me the same error. I did put the same functions in both client and server side with different prints
Based on the same logic (since you also can’t call client functions from the server) why are there even client functions in the first place? Functions, in general are good for making your code modular, improving readability, etc, doesn’t matter if it’s on the client or on the server. The client doesn’t see the address of a function defined on the server side (it sees it as nil/NULL at runtime when it is called), and that’s why you get the error.
The only way for scripts to communicate from client to server and vice versa is via events. I genuinely don’t understand why you are trying to complicate things instead of just using events. You could also just move the server code to the client?
As for shared scripts, they don’t work as you are probably thinking. Declaring a script as “shared” has the same effect as declaring it on both the client side and the server side. It will basically create 2 independent copies in memory that do not affect each other, meaning that, for example, if you modify a variable stored in the shared client script at runtime, the same shared script on the server will not be affected.
Also, your code is poorly written. What happens if you change the server’s player slots number to something greater than 48?
Hey, instead of saying everything wrong about their code, what if we decide to compliment things that they did right? The forums should be a place to help, not to tell people everything wrong such as
Also, your code is poorly written. What happens if you change the server’s player slots number to something greater than 48?
What if they didn’t know this? I understand you are asking a question but you can help them improve it, maybe give them the code to make it work?
You must be joking? Congratulations on writing a for loop. And what do you mean by “not to tell people everything wrong”? I pointed out a genuine bug that is in the code he provided. If you can’t think about basic edge cases and possible errors, you shouldn’t be developing such complex framework scripts. I also will not spoon feed anything since most people don’t learn like this, they just copy paste.
Also, this is laughable:
You clearly don’t understand that you CANNOT call server side functions from the client like this. What difference could the tostring() possibly do? Please share with us the idea behind this.
By using exports. You export a server function and then some other script can use it on its server side code. But you cannot export a server function and call it on some other script on the client side.
The testScript resource is exporting a server-sided function called testFunc. Then another resource, testScript2, will call that function using exports.testScript:testFunc() from the server side when the command testexport is executed. Now if you experiment with this and move the RegisterCommand part on a client script, you will notice that you will get a No such export ... error. Server exported functions can only be seen by other server scripts. Same for client exports and client scripts.
I finally understand now/ I’ve been around QBCore’s code, not to copy, but to learn from it, and they always call their functions inside the server scripts. I’m sorry if I’ve been hard-headed lol