I’m creating a script for a sword with multiple attacks and I’m using the raycasthibox module which is great but I’m having an issue where whenever I cast a Mouse1 attack and it doesn’t hit, the next time I cast a Mouse2 attack it will do the Mouse1 damage and vice versa.
full script:
local weapon = script.Parent
local character = weapon.Parent.Parent.Character
local hitEvent = weapon:WaitForChild("PlayerClicked")
local replicatedStorage = game:GetService("ReplicatedStorage")
local RayHitboxModule = require(replicatedStorage.RaycastHitboxV4)
local weaponHitbox = weapon:WaitForChild("Handle")
local hitbox = RayHitboxModule.new(weaponHitbox)
local M2Event = script.Parent.PlayerM2
local Mouse1CD = 1
local Mouse1DMG = 5
local Mouse2CD = 1
local Mouse2DMG = 50
--editing grip
weapon.Equipped:Connect(function()
weapon.GripPos = Vector3.new(0,0,0)
end)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local M1hitbox = RayHitboxModule.new(weaponHitbox)
M1hitbox.RaycastParams = Params
hitEvent.OnServerEvent:Connect(function()
print("Mouse1")
M1hitbox:HitStart()
wait(Mouse1CD)
M1hitbox:HitStop()
M1hitbox.OnHit:Connect(function(hit, humanoid)
local hitEnemy = hit.Parent
if hitEnemy:FindFirstChild("Blocking") then return end
print(hit)
humanoid:TakeDamage(Mouse1DMG)
end)
end)
local M2hitbox = RayHitboxModule.new(weaponHitbox)
M2hitbox.RaycastParams = Params
M2Event.OnServerEvent:Connect(function()
print("Mouse2")
M2hitbox:HitStart()
wait(Mouse2CD)
M2hitbox:HitStop()
M2hitbox.OnHit:Connect(function(hit, humanoid)
local hitEnemy = hit.Parent
if hitEnemy:FindFirstChild("Blocking") then return end
print(hit)
humanoid:TakeDamage(Mouse2DMG)
end)
end)
clip: