Any ways to imrpove this?

Well, i’m making a sword game soooo

-- // Variable
local cache = {}

-- // Modules
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitbox)

-- // Main Script
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(executor, arg) -- Get the event
	-- // Variables
	local tool = executor.Character:FindFirstChildOfClass("Tool")
	local Track = cache[executor.UserId]
	local count, isdebounce = executor.Temp.Count, executor.Temp.IsDebounce
	if not Track and arg == "M1" and count.Value == 0 and isdebounce.Value == false then
		local hitbox = RaycastHitbox:Initialize(tool.Hitbox, {executor.Character})
		cache[executor.UserId.." M1"] = executor.Character.Humanoid.Animator:LoadAnimation(tool.Config.slash1)
		cache[executor.UserId.." M1"]:Play()
		hitbox:HitStart(cache[executor.UserId.." M1"].Length - 0.1)
		local temp = hitbox.OnHit:Connect(function(hit, humanoid)
	elseif not Track and arg == "M2" then
		-- // Do block


Yes the script is server sided

It seems fine. I don’t use Ray cast Hitbox, but don’t you need to :Disconnect() the onHit at some point?

1 Like

i’ve tried, it gave me an error, so i guess it’s caused by the module :woman_shrugging:

1 Like

If it works fine without it, then whatever. I think I read somewhere that you don’t need to?