Hi, i've made a script that creates a blast in front of the player. When the ball appears and grows, it's supposed to deal damage to people (or entities) it encounters. I used the ":Touched()" function so it detects every part that touch the blast and it deals damage to its owner. However, as it detects many parts from the same player, it damages the same player more than once. Here's the script :

local transparency = 0
local blast = Instance.new("Part", game.Workspace)
blast.Shape = "Ball"
blast.CanCollide = false
blast.Anchored = true
blast.Size = Vector3.new(0.5,0.5,0.5)

blast.Touched:connect(function(hit)
	for _, char in pairs(game.Workspace:GetChildren()) do
		if char:FindFirstChild("Humanoid") then
			if hit.Parent == char or hit.Parent.Parent == char then
				if hit.Parent.Name ~= player.Name and hit.Parent.Parent.Name ~= player.Name then
					char.Humanoid:TakeDamage(50)
				end
			end
		end
	end
end)
		

for i=1,14 do
	transparency = transparency + 0.072
	blast.Transparency = transparency
	blast.Size = blast.Size + Vector3.new(1.5,1.5,1.5)
	wait()
end

5 comments

0

Use a debounce.

0

What do you mean ?

0

a debounce

0

Basically, add a wait() at the end of the script that detects/deals damage to make sure it only happens the first go.

0

you could make a table and put every person the blast hits name in it and loop through it and if the name of the collided player is not in the table, add e name and their name and do damage to them. I have no idea performance wise how good this would work though