Disable Combat when I have a Tool equipped

I am making a combat game and I am putting melees through tools and since my fist combat script is by mousebutton1 key it interferes with the tool but I want fist combat to be disabled when I have a tool equipped but I have tried several things and not may l!

Local Script:
local Player = game:GetService(“Players”).LocalPlayer
local backpack = Player:FindFirstChildOfClass(“Backpack”)

local RP = game:GetService(“ReplicatedStorage”)
local UIS = game:GetService(“UserInputService”)

local Combat = RP:WaitForChild(“Combat”)
local isBroken = script.Parent:WaitForChild(“isBroken”)

local debounce = false
local cd = .35

local currTime = 0
local prevTime = 0
local count = 0

UIS.InputBegan:Connect(function(input,isTyping)
for _, child in pairs(backpack:GetChildren()) do
if child:IsA(“Tool”).Activaded then
return
end
end

if isTyping then
	return
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
	if debounce == false and isBroken.Value == false then
		debounce = true
		currTime = tick()
		
		local passedTime = currTime - prevTime
		if passedTime < 1 then
			--Puede Continuar el Combata
			count = count + 1
			if count > 4 then
				count = 1
			end
		else
			--Tiene que repetir el Combo
			count = 1
		end
		
		Combat:FireServer(count)
		
		end
	end
end)

Combat.OnClientEvent:Connect(function()
prevTime = currTime
wait(cd)
debounce = false
end)

I have tried to do a for loops but what it does is that directly when I have a tool in the backpack I cannot use combat but I want to use combat but it is disabled when I have only the tool equipped.

1 Like

well you can make the player infinite health when equipped the tool

You want to check if the tool is inside the character when you equip a tool it exits your backpack and is parented to the Players Character

1 Like

make player regen health every second

I can check if there is a tool in the backpack with the for loops but How I make so I can check is parented to the player character? If tool.Parent == player.Character? and if that is corred what I do later I am a begginer,sorry.

Just loop through the character and check if theres a tool or not

Example:

for _, child in pairs(Player.Character:GetChildren()) do --// Looping thru Character
if child:IsA(“Tool”) then --// Checking if Instance is a Tool
--// Tool found
end

Thats what I did and I event did if child:IsA(“Tool”) and child.Parent == Player.Character then

but doesnt work

Can you show me what you did? Did you loop through the character?

Because if I remember correctly you were looping for children in the backpack which is weird
asking items parented to backpack if there parented to Character

for _, child in pairs(Player.Character:GetChildren()) do
	if child:IsA("Tool") and child.Parent == Player.Character then
		return
	end
end

Where’s proof to see if it works no prints or anything? That return would just end your function right then and there showing you nothing

So What I can do then? If that doesnt work

I said there’s no proof it works or not you didn’t attempt to debug or print or any signal to show yourself that it may have worked

for _, child in pairs(Player.Character:GetChildren()) do
	if child:IsA("Tool") and child.Parent == Player.Character then
		print("Tool Found",child)
	end
end

Try this I’ve seen some people say Instance | Roblox Creator Documentation wasn’t working for them so you can try Instance | Roblox Creator Documentation but after you’ve tested the example code I provided please.

1 Like

What I would do is something like this:

local Tool = Player.Character:FindFirstChildWhichIsA("Tool")
if Tool then return end
1 Like

It founds the tool and when I have it equipped the combat still works. :pensive:

The name of the Child wouldn’t be tool thought you would need to use Instance | Roblox Creator Documentation

1 Like

Yeah, I just noticed. I edited, mb! :smile:

That worked fine thank you! but also Thank You for extrenious for helping me too!

2 Likes

Just Add in what @OrenjiRPG Suggested and would stop the script from running before it fires combat remote you should* do the same for istyping

if isTyping then return end
local Tool = Player.Character:FindFirstChildWhichIsA("Tool")
if Tool then return end

if input.UserInputType == Enum.UserInputType.MouseButton1 then
	if debounce == false and isBroken.Value == false then
		debounce = true
		currTime = tick()
		
		local passedTime = currTime - prevTime
		if passedTime < 1 then
			--Puede Continuar el Combata
			count = count + 1
			if count > 4 then
				count = 1
			end
		else
			--Tiene que repetir el Combo
			count = 1
		end
		
		Combat:FireServer(count)
		
		end
end)
1 Like

Yeah thats what I did in the local script now I can belive all good Thank You all for the help!