So, I’m making a bot defence game. I’ve scripted the npc able to follow players, but now I need to make it do damage. I do not know how to do this. Help needed.
2 Likes
There are a couple ways you could do this
-
Using a
Touched
Event from a weapon to detect if the Enemy hit a player -
Using Magnitude/Region3 if the player is close to an enemy from an AOE standpoint
Depends on your scenario
How can I go about with the Touched Event. I would like there to be a cooldown for each hit so it doesn’t just spam you to death. Would I put in a wait?
Yeah you use a wait to delay the cooldown, I’ll show a brief code example:
local Tool = script.Parent
local Handle = Tool.Handle
local Cooldown = false
Handle.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") and Cooldown == false then
Cooldown = true
local Target = Hit.Parent
Target.Humanoid:TakeDamage(10)
wait(5)
Cooldown = false
end
end)
3 Likes
Are you talking about hitboxes of the attacks, or the AI itself telling them when to attack?
So, the ai runs into the player and deals damage.
Im looking for when the AI tells itself when to attack