Ok, so I have a script where when I click, a hitbox appears on my character, right? I want this to be a hitbox for a punch but right now, since the hitbox has a touched script inside of it, it activates multiple times when im moving instead of activating once. Normally, this would be easy to fix using debounce but the problem is I want this hitbox to affect multiple players, while only running once for each player. How do I create a script like that?
heres a gif of what i mean about the hitbox activating multiple times below: https://gyazo.com/29965352daae1a3f33610c154bcfcc1c (if you're wondering, the damage script is only supposed to deal like 15 damage, and the goal is to have the damage only applied once per player)
and heres the script im using right now:
game.ReplicatedStorage.Classes.Bubble.AbilityLMB.OnServerEvent:Connect(function(player)
local character = player.Character
local hitbox = Instance.new("Part")
local weld = Instance.new("Weld")
local selectionbox = Instance.new("SelectionBox")
selectionbox.Adornee = hitbox
selectionbox.LineThickness = 0.01
selectionbox.Color3 = Color3.fromRGB(255,0,0)
selectionbox.Parent = hitbox
hitbox.Size = Vector3.new(4.6, 4.6, 4.6)
hitbox.CanCollide = false
hitbox.Transparency = 0.6
hitbox.Color = Color3.fromRGB(100,0,0)
hitbox.Material = Enum.Material.Neon
hitbox.Shape = Enum.PartType.Ball
hitbox.Parent = character
weld.Part0 = hitbox
weld.Part1 = character.HumanoidRootPart
weld.Parent = hitbox
local hitdamage
hitdamage = hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Name ~= character.Name then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health - 15
end
end
end)
wait(0.3)
if hitdamage ~= nil then hitdamage:Disconnect() end
hitbox:Destroy()
end)
