How to make a 1 Hit system

Hey There I’m making a game on Roblox that revolves around these types of magics called Arts and an important factor of the game is making these “Arts” as efficient as possible.

An important aspect that I want to implement is a projectile only hitting a player or NPC once.

As you know with the . Touched Function if a player gets hit by the projectile it will rapidly say that it hits the player and cause the Touched function to run multiple times which is good in some cases but for my case, it’s not that great. In the meanwhile what I have been doing to combat this is using a tag system where I create a bool value on the first hit of the projectile and have the projectile check if the tag exists before applying the effects of the art but I’m wondering if there is a better way to do this


local Projectile = game.ReplicatedStorage.DarkMagic.DarkSpike:Clone()

Projectile.Touched:Connect(function(Hit)
	
	if Hit:FindFirstChild("Humanoid") and Hit:FindFirstChild("Tag_"..plr.UserId) == nil then 
		local Tag = Instance.new("BoolValue")
		Tag.Name = "Tag_"..plr.UserId
		Tag.Parent = Hit.Parent
		
		--Where i would implement art logic
	end
end)

      

Feel free to let me know!

Thank you!

I see you have the player defined, so starting from there you can just create a Debounces table, which is basically what you’re doing, but without creating extra instances.

local Debounces = { }

Projectile.Touched:Connect(function(Hit)
	if Debounces[plr.UserId] then return end
	Debounces[plr.UserId] = true
end)

-- table.clear(Debounces) -- To clear all debounces
3 Likes

This debounce table will persist for all projectiles, it’ll need to be reset/emptied each time a new projectile is created/the previous projectile is removed/cleared. Unless each projectile is handled by its own script but that’d be fairly inefficient.

Yes im making sure i clear the table when the projectile gets destroyed and when its created. Thank you!