the bat works fine at first but at times it will bug out for some reason and not play or do damage
video will show the bug and without the bug
local script
task.wait(.1)
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitboxV4)
local tool = script.Parent
local players = game:GetService("Players").LocalPlayer
local character = players.Character or players.CharacterAdded:Wait()
local humanoid:Humanoid = character:WaitForChild("Humanoid")
local remote = tool:WaitForChild("Events"):WaitForChild("GetPlayerOnHit")
local animations = {
Equip = tool:WaitForChild("Animations"):WaitForChild("Equip"),
Idle = tool:WaitForChild("Animations"):WaitForChild("Idle"),
Swing = tool:WaitForChild("Animations"):WaitForChild("Swing")
}
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {character,tool}
Params.FilterType = Enum.RaycastFilterType.Exclude
local Hitbox = RaycastHitbox.new(tool)
Hitbox.RaycastParams = Params
Hitbox.DetectionMode = RaycastHitbox.DetectionMode.Default
Hitbox.Visualizer = true
local equiptrack:AnimationTrack = humanoid.Animator:LoadAnimation(animations.Equip)
local idletrack:AnimationTrack = humanoid.Animator:LoadAnimation(animations.Idle)
local swingtrack:AnimationTrack = humanoid.Animator:LoadAnimation(animations.Swing)
idletrack.Priority = Enum.AnimationPriority.Idle
swingtrack.Priority = Enum.AnimationPriority.Action4
local debouce = false
tool.Equipped:Connect(function()
equiptrack:Play()
idletrack:Play()
end)
tool.Unequipped:Connect(function()
equiptrack:Stop()
idletrack:Stop()
end)
tool.Activated:Connect(function()
if debouce then return end
debouce = true
swingtrack:Play()
task.wait()
debouce = false
end)
Hitbox.OnHit:Connect(function(hit, targetHum)
if targetHum then
Hitbox:HitStop()
remote:FireServer(targetHum,5)
end
end)
swingtrack:GetMarkerReachedSignal("OnHit"):Connect(function()
Hitbox:HitStart(.2)
end)
server script
task.wait(.1)
local tool = script.Parent
local motor:Motor6D = tool.Motor6D
local character = tool.Parent
--motor.Part0 = tool.Handle
--motor.Part1 = tool.Parent.Parent.Name
local remote = tool:WaitForChild("Events"):WaitForChild("GetPlayerOnHit")
local trail: Trail = tool.Handle:WaitForChild("Trail")
--//SFX//--
local equipsfx = tool.Handle.Equip
local hitsfx = tool.Handle.Hit
local hitsfx2 = tool.Handle.Hit2
local hitsfx3 = tool.Handle.Hit3
local hitsfx4 = tool.Handle.Hit4
local swooshsfx = tool.Handle.Swoosh
local function playsound(a,b,c,d)
local rand = math.random(1,4)
if rand == 1 then
a:Play()
elseif rand == 2 then
b:Play()
elseif rand == 3 then
c:Play()
elseif rand == 4 then
d:Play()
end
end
local function trailset()
trail.Enabled = true
task.wait(.4)
trail.Enabled = false
end
tool.Equipped:Connect(function()
equipsfx:Play()
end)
tool.Unequipped:Connect(function()
end)
tool.Activated:Connect(function()
swooshsfx:Play()
trailset()
end)
remote.OnServerEvent:Connect(function(Player,targetHum,Damage)
targetHum:TakeDamage(Damage)
hitsfx.Parent = targetHum
hitsfx2.Parent = targetHum
hitsfx3.Parent = targetHum
hitsfx4.Parent = targetHum
playsound(hitsfx,hitsfx2,hitsfx3,hitsfx4)
local character = targetHum.Parent
end)
if anyone could help me with this it would greatly be appreciated