Can functions inside a serversided module script be called from a local script

So Iam working on a local script that basicly has to fire a function in a serversided module script when a player clicks on the screen. Obviously local scripts can’t access the serverstorage, so I tried putting the module script inside the replicatedstorage, but appearantly then the module script also can’t access the serverstorage, and it has to be able to do that. So Iam wondering if there is a way that local scripts can call functions from a serversided modulescript. If not then if there is any other possible way of firing functions from a serversided module script when a player clicks on the screen.

script inside local script:

local HitModule = require(game.ServerScriptService:WaitForChild("HitModule"))
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, used)
	if used == true then

	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Clicked")
		
        if drop == nil then
			print("Not touching a drop")
		else
			print("Hitting drop!")
			local newCoroutine = coroutine.wrap(HitModule.Hit)
			newCoroutine(player, drop)
		end
	end
end)
1 Like

Can’t you use remote events? char limit

1 Like

Is possible, but i try to avoid them because exploiters can easily exploit them. I know that there are not many exploiters lefts but I still want to use other ways if there are any. Otherwise I guess they are my only option.

1 Like

Yeah it’s kinda the only thing you can do.

1 Like

Yea alright, Thanks for the reply. I think Iam left with nothing more. I will think if I can make a way to check if the events are legit, otherwise I guess I will have to life with the fact that exploiters can exploit easy.

1 Like

Remotes are an inherent part of any game. They are not exploitable or dangerous by themselves, only if they’re used in such a way.

For instance, remote events from client to server give the exploiters as much power as the connected function gives them. Suppose there is a button to add a coin into the player’s wallet. The player presses the button, fires a remote signal, and the server adds a coin. To prevent spamming (exploitable vulnerability), the server adds a short cooldown between requests. Furthermore, the server as an authority adds a coin. If the server was to add a value client sent (1 in the client code), the situation would indeed be exploitable, as the exploiter could send an arbitrary value.


Regarding module scripts: Each computer (the server/host, the clients) has its own version, own environments etc. A module required in a local script runs as client code; a module required in a server script is executed on the server.


Unrelated side note

This is a coroutine in a coroutine, because :Connect() already spawns one.

2 Likes

Yea I know but the functions that my local calls are kinda valuable because it is for taking damage to a drop (like in simulator games like pet sim). Now the functions requires a dropid as a parameter so for exploiters it is easy to loop trough all the drops in the workspace and basicly call the hitfunction for it. Now the damage value is located at a save place so they can only make a script that will break all the drops.

Ofcourse Iam going to try to make a anticheat for this no worries, I got some tricks. But I was just thinking if there was an easier way to do this. Appearantly not so i’ll just have to take some more time to make this.

Thank you for the relpy tho!

1 Like

I should probably explain the dynamics of server-sided security for the sake of this thread.

The only reason a remote event (or in this case a remote function) would be exploitable is if there is information that the client can send to the server to make the function exploitable. The less information being sent from the client, the less malleable the code is on the server.

The problem isn’t how exploitable something is from the client but how tight the security is on the server when information from the client is provided. To do what you wish to do, you would likely need to use a RemoteFunction or RemoteEvent.

Even after reading I admittedly do not understand what you’re trying to achieve but if you can explain it in a way for me to understand it better I can give you the necessary context and/or solution to your question.

1 Like

The thing I want to achieve is a local script that can call functions from a module script.

Now there is a high possibility that this isn’t possible and that I will have to do this with remote events/functions. Which isn’t that big of a deal because, like you said, I just have to use them right and not make them a possible break for exploiters.

But I just made this post to check if it is possible in a way to call functions inside a module script in the ServerScriptService from a LocalScript inside StarterPlayer (aka a player). Because then it would be easier for me to make the system I want to make.

Now if this isn’t possible I will just use remote events.

Think of a module as a means to store code and more easily access it. A module will run code through the same environment that it is called from because all a script is doing is accessing the code stored in the module and “running it” on its own.

That said, if you call a module from a local script it will retain the local environment. Remotes are designed specifically for the purpose you desire and exclusively so.

There’s no way to breach that barrier (which is important because if the client could access server run code through a module exploiters could abuse it.)