How would i make activating skills like tsbg?

currently, ive got this for firing a remote event when the player clicks m1

uis.InputBegan:Connect(function(key, typing)
	if typing then return end
	if key.UserInputType == Enum.UserInputType.MouseButton1 then
		m1signal:FireServer(true)
	end

but it mixes with activating a tool

tool.Activated:Connect(function()
	Slash:FireServer()
end)

is there any way i can prevent m1s being used while the tool is equipped?

1 Like

If these are located in the same script, The most simple way to fix this would be to add a flag to track the tool being equipped, and unequipped.
Then in the inputbegan function, at the

if key.UserInputType == Enum.UserInputType.MouseButton1 then

You can do:

if key.UserInputType == Enum.UserInputType.MouseButton1 and not toolEquipped then

Full fixed script example:

local uis = game:GetService("UserInputService")
local tool = script.Parent -- Replace with the correct tool reference
local toolEquipped = false

-- Detect M1 click only when tool is not equipped
uis.InputBegan:Connect(function(key, typing)
	if typing then return end
	if key.UserInputType == Enum.UserInputType.MouseButton1 and not toolEquipped then
		m1signal:FireServer(true)
	end
end)

-- Handle tool equipped and unequipped states
tool.Equipped:Connect(function()
	toolEquipped = true
end)

tool.Unequipped:Connect(function()
	toolEquipped = false
end)

-- Tool-specific action
tool.Activated:Connect(function()
	Slash:FireServer()
end)

If they are in separate scripts, one thing to note is that tools when equipped get replicated to the character model, and then removes itself from char model when unequipped.

So you could add a check inside of the input began function like:

if key.UserInputType == Enum.UserInputType.MouseButton1 and not char:FindFirstChild("[toolname]") then

Let me know if this works or not.

it worked! thank you very much :smile:

1 Like

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