My combat uses no tool, so whenever a tool is equipped it doesn’t stop, so I can’t use the other tools in my toolbox properly.
I tried using a return, it didn’t work so could anyone help me?
local Event = game.ReplicatedStorage:WaitForChild("CombatRemote"):WaitForChild("Combat")
local TS = game.TweenService
local cameraShaker = require(game.ReplicatedStorage.CameraShaker)
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local debounce = false
local CD = .3
local currTime = 0
local prevTime = 0
local count = 0
local canAir = false
local State = nil
local hum = char:WaitForChild("Humanoid")
hum.StateChanged:Connect(function(oldState, newState)
State = newState
if newState == Enum.HumanoidStateType.Jumping then
canAir = true
else
canAir = false
end
end)
local camShake = cameraShaker.new(Enum.RenderPriority.Camera.Value,function(ShakeCF)
Camera.CFrame = Camera.CFrame * ShakeCF
end)
game.ReplicatedStorage.CamShake.OnClientEvent:Connect(function(magnitude,roughness,fadeIn,fadeOut,lenght)
camShake:Start()
camShake:ShakeOnce(magnitude,roughness,fadeIn,fadeOut)
wait(lenght)
camShake:Stop()
end)
local Tool = player.Character:FindFirstChildWhichIsA("Tool")
if Tool then return end
mouse.Button1Down:Connect(function()
if char:FindFirstChild("CanAttack").Value == true and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil and char:FindFirstChild("IsBlocking") == nil and char:FindFirstChild("BlockBreak") == nil then
if debounce == false then
debounce = true
currTime = tick()
local passedtime = currTime - prevTime
camShake:ShakeOnce(1,1,1,1)
if passedtime < 1 then
------- Can Cuntinue the Combat Combo
count = count + 1
if count > 5 then
count = 1
end
else
---Restarts the Combo
count = 1
end
Event:FireServer(count,canAir,State)
end
end
end)
Event.OnClientEvent:Connect(function(plr,newcount)
wait(CD)
prevTime = currTime
debounce = false
end) ```
This is a script I like to use a lot in my tools :3
if not script.Parent.Parent:IsA("Model") then
while true do
script.Parent.AncestryChanged:Wait()
if script.Parent.Parent:IsA("Model") then
break
end
end
end
Alright so it worked, but after equipping and removing the tool the combat doesn’t work. Basically when I stop equipping the tool, the combat doesn’t work here’s the script
local Event = game.ReplicatedStorage:WaitForChild("CombatRemote"):WaitForChild("Combat")
local TS = game.TweenService
local cameraShaker = require(game.ReplicatedStorage.CameraShaker)
local Camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.CharacterAdded:Wait()
local debounce = false
local CD = .3
local currTime = 0
local prevTime = 0
local count = 0
local canAir = false
local State = nil
local hum = char:WaitForChild("Humanoid")
hum.StateChanged:Connect(function(oldState, newState)
State = newState
if newState == Enum.HumanoidStateType.Jumping then
canAir = true
else
canAir = false
end
end)
local camShake = cameraShaker.new(Enum.RenderPriority.Camera.Value,function(ShakeCF)
Camera.CFrame = Camera.CFrame * ShakeCF
end)
game.ReplicatedStorage.CamShake.OnClientEvent:Connect(function(magnitude,roughness,fadeIn,fadeOut,lenght)
camShake:Start()
camShake:ShakeOnce(magnitude,roughness,fadeIn,fadeOut)
wait(lenght)
camShake:Stop()
end)
local hum = char:WaitForChild("Humanoid")
player.Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
char:FindFirstChild("CanAttack").Value = false
elseif child:IsA("Tool") == false then
return
end
end)
mouse.Button1Down:Connect(function()
if char:FindFirstChild("CanAttack").Value == true and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil and char:FindFirstChild("IsBlocking") == nil and char:FindFirstChild("BlockBreak") == nil then
if debounce == false then
debounce = true
currTime = tick()
local passedtime = currTime - prevTime
camShake:ShakeOnce(1,1,1,1)
if passedtime < 1 then
------- Can Cuntinue the Combat Combo
count = count + 1
if count > 5 then
count = 1
end
else
---Restarts the Combo
count = 1
end
Event:FireServer(count,canAir,State)
end
end
end)
Event.OnClientEvent:Connect(function(plr,newcount)
wait(CD)
prevTime = currTime
debounce = false
end)```
There is another event called “ChildRemoved” and you can use it as shown below.
Just put it below your ChildAdded function.
You can also simplify your code as shown below:
player.Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
char:FindFirstChild("CanAttack").Value = false
end
end)
player.Character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
char:FindFirstChild("CanAttack").Value = true
end
end)