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)
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.
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
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
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
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)