Help on using module scripts for tool actions

Hey! so im making a weapon system for my game, my friend told me to use module scripts that works like tools but are inside a folder inside the player, instead of in the tool.

The problem im running at is the player switches tools every round, for example when he is in the lobby he has no tool, but when he is in a match he gets the tool, how would i make the modules work for that?
Thanks in advance :slight_smile:

Hey !

You can make a different module which handle each different tools, just name the module as the same tool name he’s handling, then by using a Script in ServerScriptService, you can check when a tool is added in character and require the right module.

Here is an example:

--//Services//--
local PlayerService = game:GetService("Players")

--//Functions//--
local function ToolActivated(Tool)
	local Module = script:FindFirstChild(Tool.Name)
	if Module then
		coroutine.resume(coroutine.create(function()
			require(Module).Activated()
		end))
	end
end

local function ToolsCheck(Character)
	Character.ChildAdded:Connect(function(Tool)
		if Tool:IsA("Tool")then
			Tool.Activated:Connect(function()
				ToolActivated(Tool)
			end)
		end
	end)
end

--//Connections//--
workspace.ChildAdded:Connect(function(Character)
	if Character:IsA("Model")and PlayerService:FindFirstChild(Character.Name)then
		ToolsCheck(Character)
	end
end)
1 Like

Just tested it and it worked, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.