Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way i can prevent this script from damaging the same humanoid twice?

So i want to prevent this script from damaging the same humanoid twice while still being able to damage other ones, just not multiple times.

wait()

script.Parent.Touched:Connect(function(hit)
	
	local h = hit.Parent:FindFirstChild("Humanoid")
	
	local dmg = 15
	
	if h~=nil then
	
		
		h:TakeDamage(dmg)
		
		
		
		end

	
	
end)

1 answer

✓ Accepted answer

I'd set up a table and store the names of who has been hit.

local touched = {}
script.Parent.Touched:Connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") then
		for _, v in pairs(touched) do
			if v == h.Parent.Name then else
				h.Parent.Humanoid:TakeDamage(15)
				table.insert(touched,h.Parent.Name)
			end
		end
	end
end)

This adds the players name to "touched" then once script.Parent is touched, it checks if the name is in the table and decides to take damage if it isn't there..

If this works, click accept, thanks

8 comments

0

Oh by the way, to reset the table, put this in the script anywhere --> touched = {}

0

Doesn't seem to be doing any damage, i'm trying to find the error but there doesn't seem to be any.

0

strange, add a wait(3) to the top and tell me if you find any errors

0

no errors, but it doesn't work either

0

OOOH IK WHY, TRY NOW!!!

0

I forgot ".Parent" I am so clumsy ;(

0

Ik i saw that but even after i changed it, still nothing :(

0

Try debugging it with prints...

This discussion is preserved as it was. New answers, comments, and votes are closed.