The code on the video is a bit quirky.

It is a function that uhh, I’d not recommend using. I’d first gravitate towards doing a system on my own instead of going from a YouTube video, they normally don’t have the best code, its like a canvas you can paint on top of, but not just leave as-is, the reason this is bad is because you are making a connection just for a one time usage. This is not required, the Documentation CLEARLY notes that you only need to enable CanCollide to true, if it was false, the code would also not work anyway, so the thing it is doing, is useless anyway.
I’d rewrite the code like this (And I’ll just made a code dump, becuase I don’t want to make a really creative text being that it comes from a YouTube video and is not yours necessarily, but I will still break down the code a bit).
First of all, no shorting of variable names. Variable names such as RS are complete and utter garbage, they make your code VERY easy to confuse. RS could mean RunService or ReplicatedStorage, this is not really a good thing at all, another source of critisism also comes from using pairs. Why you may ask? Luau has a faster way, which is just NOT using pairs, luau very much deprecated iterator functions (ipairs, pairs, next) when they added the __iter metamethod. This version also attempts to address some possible behaviours that might not be alright, I’d recommend you to test the code before you just use it, and try to understand it, it is commented out with some explanations as to why some things are done, I wrote this quickly, so uhh, don’t trust it much!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Not used?
-- local DebrisService = game:GetService("Debris")
local PlayerService = game:GetService("Players")
local hitbox = ReplicatedStorage.Hitbox
local specialRE = ReplicatedStorage.SpecialRE
specialRE.OnServerEvent:Connect(function(player: Player)
local playerCharacter = player.Character
local attackingPart = "Right Arm"
local hClone = hitbox:Clone()
-- Not used?
-- local hCFrame = playerCharacter[attackingPart].CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = hClone
weld.Part0 = hClone
weld.Part1 = playerCharacter[attackingPart]
local collidedPlayers = {}
hClone.CanCollide = true -- Assure that GetTouchingParts works as expected
task.wait()
for _, part in (hClone:GetTouchingParts()) do -- pairs is not necessary. Luau has the __iter metamethod, making iterator functions useless.
local suspectedCharacter: Instance = part.Parent
local loopPlayer = PlayerService:GetPlayerFromCharacter(suspectedCharacter)
if not loopPlayer then
warn("[SpecialRE::OnServerEvent] Touching part is not that of a player?")
continue
end
-- Using PlayerService we can get the player that is going to be the target of the hitbox, making this more reliable.
if not table.find(collidedPlayers, loopPlayer) then -- Shorten hum ~= nil into hum, it will go through if it is not nil or false.
table.insert(collidedPlayers, loopPlayer)
end
end
hClone:Destroy()
for _, loopPlayer: Player in pairs(collidedPlayers) do
local humanoid = loopPlayer.Character:FindFirstAncestorOfClass("Humanoid")
if not humanoid then
warn("Player has no humanoid?")
continue
end
humanoid:TakeDamage(20)
end
end)