Don't know if the subject is clear enough/understandable but I'd like to make a touch function that can damages multiple players at once but will only hit a each player once and/or hit them again after a set amount of time during that touch. The current code I have is this:
function Hit(part)
[Not relevant coding]
[Other assets to find]
local HitByYou = part.Parent:FindFirstChild("HitBy"..player.Name.."")
if [Find Assets] then
if hum1.Parent.Name == char.Name or game.Players[hum1.Parent.Name].TeamColor == player.TeamColor then
[Not relevant coding]
else
if HitByYou ~= nil then
else
ActionText = Damage
ActionTextPosition = hum1.Parent.Head.Position
MakeText()
local hitbyyou = Instance.new("StringValue")
hitbyyou.Parent = hum1.Parent
hitbyyou.Name = "HitBy"..player.Name..""
hum1.Health = hum1.Health-Damage
wait(DamageFrame)
hitbyyou:remove()
end
end
end
end
if npc1 and Atk and Blk and Clh and KBCO and Kb and Kbf and Tc then
if npc1.Parent.Name == char.Name or Tc.Value == player.TeamColor then
else
if Blk.Value == true then
KnockedBack.Value = true
KBCoolOff.Value = 1
KBForce.Value = -60
ActionText = "Blocked"
ActionTextPosition = npc1.Parent.Head.Position
MakeText()
elseif Clh.Value == true then
print("lol no you're not allowed to do that. :)")
KnockedBack.Value = true
KBCoolOff.Value = .6
KBForce.Value = -60
else
print(HitByYou)
if HitByYou ~= nil then
else
ActionText = Damage
ActionTextPosition = npc1.Parent.Head.Position
MakeText()
local hitbyyou = Instance.new("StringValue")
hitbyyou.Parent = npc1.Parent
hitbyyou.Name = "HitBy"..player.Name..""
npc1.Health = npc1.Health-Damage
game:GetService("Debris"):AddItem(hitbyyou, DamageFrame)
end--]]
end
end
end
end
end
end
DamageBox.Touched:connect(Hit)
I have the print(HitByYou) so I could see if it was nil or not. When I checked the Output it printed nil and HitByYou constantly, but when it printed HitByYou it was more than once. Are there any better methods at restricting hits to one player? |