Hi so I’m looking to make a holdable key to make a choke ability but using modules, I have no idea where to start or what to even put in the scripts and looking for someone to tell me how exactly I would do it
You can think of module scripts as Functions
but in a separate script, that you can call from any other script; with the use of require()
.
In your case, you can create the ability function within the module script, and then call the function whenever the player presses/holds the key in a different script.
You can learn more about Module Scripts
here:
Thankyou, However I’m confused about one thing if I set up a UIS in a local script then used the function after pressing the key would the effects and everything be visible to all players or only that player?
typeof() → unknown → secret
Module scripts called from a Local Script
will run the code locally, which means the code will not be replicated to the server. Instead, I would recommend that you use remote events.
Remote events are used to replicate code from Local scripts
to the server, which will replicate to all users.
Create a remote event in Replicated Storage
and call the remote event from within your Local Script
, which will then connect to the main script that you are using for the ability.
Local script
local event = game:GetService("ReplicatedStorage"):FindFirstChild("Event")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
event:FireServer() -- Insert necessary code inside the event as arguments
end
end)
Server script
or your main script
local events = game:GetService("ReplicatedStorage"):FindFirstChild("Event")
-- Player is automatically assigned as a parameter
events.OnServerEvent:Connect(function(player)
-- Run necessary code/module script code
end)
You can learn more about Remote Events here:
DeprecatedModuleScript is an s data type from Roblox.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.