How to get the function?

so like im trying to make a " Damage Hit Marker " type of deal

here’s my current code

local hit = {}
damagevisualevent.OnClientEvent:Connect(function(place,damage,Enemy:Instance)
	if player.PlayerScripts:FindFirstChild("PlayerSettings"):FindFirstChild("VisualizeDamage").Value == true then
		local ehum = Enemy:FindFirstChild("Humanoid")
		if ehum and ehum.Health > 0 then
			if not table.find(hit,{Enemy}) then
				local Localdamage = -(ehum.Health - damage) + ehum.Health
				table.insert(hit,{Enemy;dmg = createdvb(Localdamage,place)})
				
				print("found nothing")
			else
				print("found something")
			end
		end
	else
		return
	end
end)

im trying to like get that function that returns a part, ive scrolled around dev forums and youtube but i haven’t found anything similar to my code

the current code always simply returns the “found nothing” part and not the “found something” part

sorry. im new.

1 Like

In your table.insert, you’re effectively adding this to the table:

{part, dmg = 100}

You’re searching for this in your table.find though:

part

A better way to do this is to use dictionaries instead of tables, and just index into them to check/insert values.

Code:

local hit = {}

damagevisualevent.OnClientEvent:Connect(function(place, damage, Enemy:Instance)
	if not player.PlayerScripts:FindFirstChild("PlayerSettings"):FindFirstChild("VisualizeDamage").Value then
		return
	end
	
	local ehum = Enemy:FindFirstChild("Humanoid")
	
	if not ehum or ehum.Health <= 0 then
		print("Invalid Enemy Humanoid")
		
		return
	end
	
	if hit[Enemy] then
		print("found something")
	else
		local localDamage = -(ehum.Health - damage) + ehum.Health
		hit[Enemy] = createdvb(localDamage, place)

		print("found nothing")
	end
end)

I also added some guard clauses.

1 Like

im going to try and mash this with my code ill come back with results, thank you!

Edit: works!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.