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
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)