-- MODULESCRIPT CODE --
local module = {} -- notice how this is what a table looks like?
-------------
--\SERVICE\--
-------------
local TS = game:GetService("TweenService")
-----------------------
---this effect functions controls the tower effect aesthetic
--nothing to explain here other than that it just controls
--the tower effect aesthetic.
-----------------------
local function EffectsControl(arguement1,effects)
effects.Shoot:Play()
if arguement1 == "Fire" then
effects.Effect1.MuzzleEffect.Enabled = true
return effects.Effect1.MuzzleEffect
end
end
-----------------------
---this Animate function controls the tower animation.
--nothing to explain here other than that it just controls
--the tower animation.
-----------------------
local function Animate(hum,Animation,animateId)
--updates animationid to passed arguement1.
Animation.AnimationId = animateId
--loads the new animationId
local loadanimation = hum:LoadAnimation(Animation)
loadanimation:Play()
--sets the global variable to loaded animation.
return loadanimation
end
-----------------------
---this attack functions controls the attack function
--nothing to explain here other than that it just controls
--how it attacks.
-----------------------
function Attack(model,bullettype,enemy,Base)
local model_stats = model.Stat;
local Animation = model_stats.Animation;
local damage = model_stats.Damage;
local hum = model.AnimationController.Animator;
local effect = model.Weapon.Effects
local returned_val = EffectsControl("Fire",effect)
local hitbox = Instance.new("Part")
hitbox.Size = model.Weapon.Size hitbox.CanCollide = false
--\\
hitbox.CFrame = CFrame.new(enemy.PrimaryPart.Position,model.PrimaryPart.Position);
--\\
hitbox.Position = model.Weapon.Position hitbox.Parent = game.Workspace
bullettype.BulletMesh:Clone().Parent = hitbox
model:SetPrimaryPartCFrame(
CFrame.new(
model.PrimaryPart.Position,
Vector3.new(
enemy.PrimaryPart.Position.X,
model.PrimaryPart.Position.Y,
enemy.PrimaryPart.Position.Z
)
)
)
if bullettype.Value == "Fist" or
bullettype.Value == "Knife"
then
hitbox.Position = model.Weapon.Position
local weld = Instance.new("Weld")
weld.Part0 = model.Weapon
weld.Part1 = hitbox
weld.Parent = model.Weapon
elseif bullettype.Value == "Bullet" then
hitbox.Position = model.PrimaryPart.Position
hitbox.Velocity = model.PrimaryPart.CFrame.LookVector*190
end
hitbox.Touched:Connect(function(hit)
if hit.Parent ~= nil
and hit.Parent ~= model
and hit.Parent:FindFirstChild("Stat") ~= nil
and hit.Parent.Stat.Role.Value ~= Base
then
hit.Parent.Stat.Health.Value-=damage.Value
hitbox:Destroy()
end
end)
Animate(hum,Animation,Animation.ShootAnimation.Value).Stopped:Wait()
if returned_val ~= nil then
returned_val.Enabled = false
end
hitbox:Destroy()
end
-----------------------
---this move functions controls the tower
--about movements. it will make the tower go
--through each path,
--the model arguement is a arguement that was passed.
-----------------------
function Move(model,Map)
local position = nil
local targetPos = 1
local source = Map.Roads.Road:GetChildren()
local walkspeed = TweenInfo.new(
model.Stat.Walkspeed.Value,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut
)
for i, target in pairs(source) do
if target.Name == tostring(targetPos) then
print(target.Name)
position = target.Position
break
end
end
local walk = TS:Create(
model.PrimaryPart,
walkspeed,
{CFrame =
CFrame.new(Vector3.new(position.X,position.Y+1.075,position.Z)) *
CFrame.Angles(0,math.rad(90),0)
}
)
walk:Play()
walk.Completed:Connect(function(didArrive)
if not didArrive then
warn("not arrive")
end
--selects the next target
targetPos += 1
if targetPos <= #source then
Move()
else
print("Done moving!")
end
end)
return walk
end
-----------------------
---this action function controls how the tower works
--it will call the 2 function above to depending on what moves.value
--it finds.
--the arguement1 tells wether the tower should move or not
--enemy is a enemy model, another arguement.
--model is the towermodel. enemy and model will be used
--to pass onto another function it will call.
-----------------------
function Actions(arguement1,enemy,model,Map)
local model_stat = model.Stat
local bullettype = model_stat:FindFirstChild("BulletType")
local base = model_stat.Role
local move = model_stat.Moves
if string.find(move.Value,"Walk")
and string.find(move.Value,"Summon")
then
Move(model,Map)
end
if string.find(move.Value,"Attack") then
Attack(model,bullettype,enemy,base.Value)
end
end
-----------------------
---this controls the tower finding targets
--nothing to explain here other than that it controls how the tower
--finds the target.
-----------------------
function findTarg(range,cooldown,enemies,towermodel,targettype,Map)
print("im getting calls")
local thread = coroutine.create(function()
print("a new thread.")
local nearby = {}
local Map = Map
local baseFolder = Map[towermodel.Stat.Role.Value]
local debounce = false
print(Map,baseFolder,debounce)
while wait(cooldown.Value) do
print("while loops")
for i, enemy in pairs(enemies:GetChildren()) do
if (towermodel.PrimaryPart.Position -
enemy.PrimaryPart.Position).magnitude <= range.Value
and enemy ~= nil
then
if targettype.Value == "First" then
table.remove(nearby, 1)
table.insert(nearby, enemy)
--targets enemy in its eyes
elseif targettype.Value == "Ray" then
--creates ray.
local ray = workspace:FindPartOnRayWithIgnoreList(Ray.new(
Vector3.new(towermodel.PrimaryPart.Position.X+0.5,
towermodel.PrimaryPart.Position.Y,towermodel.PrimaryPart.Position.Z
),
towermodel.PrimaryPart.CFrame.lookVector * 12),
{Map.Roads,baseFolder}
)
--indicates that the ray is looking
--at the enemy.
if ray ~= nil and ray.Parent == enemy then
table.remove(nearby, 1)
table.insert(nearby, enemy)
end
end
if debounce == false then
Actions(true,nearby[1],towermodel,Map)
end
end
end
--]]
end
end)
return thread
end
function module.Hitman(towermodel,enemyfolder,Map)
print("YE")
local stat = towermodel.Stat
local range = stat.Range
local cooldown = stat.Cooldown
local enemies = enemyfolder
local targettype = stat.targetType
local hum = towermodel.AnimationController.Animator
local loadanimation = hum:LoadAnimation(stat.Animation.AnimationId)
loadanimation:Play()
print(range,cooldown,enemies,targettype)
coroutine.resume(findTarg(range,cooldown,enemies,towermodel,targettype,Map))
--//loads idle animation first.
--Animate(stat.Animation.AnimationId)
print("skips oooo")
end
--[[
local cooldown = stats:FindFirstChild("Cooldown");
local damage = stats:FindFirstChild("Damage");
local bulletType = stats:FindFirstChild("BulletType");
local health = stats:FindFirstChild("Health");
local unique = stats:FindFirstChild("Unique")
local targettype = stats:FindFirstChild("targetType")
local role = stats:FindFirstChild("Role")
local range = stats:FindFirstChild("Range")
local moves = stats:FindFirstChild("Moves")
]]
return module
the error line is in the module.Hitman where i try to load animation and the coroutine doesn’t get resumed.