idk why my ignorelist is not working i want to make my hitbox not hitting the same user over and over again
local hitbox = script.Hitbox:Clone()
hitbox.Parent = workspace
hitbox.CFrame = standrootpart.CFrame
hitbox.Touched:Connect(function(hitpart)
if not hitpart:IsDescendantOf(char) then
if hitpart.Parent:FindFirstChild("Humanoid") then
local enemy = hitpart.Parent
local enemys = players:GetPlayerFromCharacter(enemy)
enemy.HumanoidRootPart.CFrame = CFrame.new(enemy.HumanoidRootPart.Position, char.HumanoidRootPart.Position)
local HFX = script.HitSound:Clone()
HFX.Parent = enemy
local ignorelist = {}
if (table.find(ignorelist,enemy) == nil) then
table.insert(ignorelist,enemy)
table.insert(ignorelist,enemy)
The problem here boils down to the scope of your local variable ignorelist. Notice where you’ve placed ignorelist with respect to the rest of your code- ignorelist is defined within the Touched event. A local variable can only be used within the scope in which it is defined, so having ignorelist within the Touched event implies that for every time the code in the Touched event finishes running, the local variable will cease to exist.
To fix this, I suggest moving your variable declaration to somewhere more appropriate for the circumstance. This means move it outside of the event. Based on the code snippet you’ve presented here, I would say an appropriate location would be right after you change the properties of hitbox and before its Touched event declaration.
local hitbox = script.Hitbox:Clone()
hitbox.Parent = workspace
hitbox.CFrame = standrootpart.CFrame
local ignorelist = {}
hitbox.Touched:Connect(function(hitpart)
if not hitpart:IsDescendantOf(char) then
if hitpart.Parent:FindFirstChild("Humanoid") then
local enemy = hitpart.Parent
local enemys = players:GetPlayerFromCharacter(enemy)
enemy.HumanoidRootPart.CFrame = CFrame.new(enemy.HumanoidRootPart.Position, char.HumanoidRootPart.Position)
local HFX = script.HitSound:Clone()
HFX.Parent = enemy
if (table.find(ignorelist,enemy) == nil) then
table.insert(ignorelist,enemy)
Hope this helps. Let me know if you have any questions.