Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PathFindingService = game:GetService("PathfindingService")
- local UIS = game:GetService("UserInputService")
- local event = game.ReplicatedStorage.MageAttacks.Attack:WaitForChild("AttackEvent")
- local rStorage = game:GetService("ReplicatedStorage")
- local remoteFunction = rStorage.MageAttacks.Attack:WaitForChild("AttackFunction")
- local animation = Instance.new("Animation")
- animation.AnimationId = "http://www.roblox.com/asset/?id=1379182293"
- local player = game.Players.LocalPlayer
- local char = player.Character
- local hum = char.Humanoid
- local mouse = player:GetMouse()
- local end_p = nil
- local moving = false
- local attacking = false
- local enabled = true
- local my_target = nil
- local path = nil
- local waypoints = nil
- hum.WalkSpeed = char.Speed.Value
- function Find_Obj()
- local target = nil
- if mouse.Target.Parent.Parent.Name == "IceMinions" then
- print("yes")
- target = mouse.Target.Parent.UpperTorso
- return target
- elseif mouse.Target.Parent.Parent.Name == "Firetowers" then
- target = mouse.Target.Parent.UpperTorso
- return target
- else
- target = nil
- end
- end
- function distance_to_object(obj)
- local total = nil
- if obj then
- local magn = (obj.Position - char.UpperTorso.Position).magnitude
- total = magn
- end
- return total
- end
- function stop_start_moving(stop, start)
- if stop == true and start == false then
- start = false
- hum.WalkSpeed = 0
- elseif start == true and stop == false then
- stop = false
- hum.WalkSpeed = char.Speed.Value
- end
- end
- local function onKeyPress(target)
- if not enabled then return end
- if attacking == false then return end
- local animTrack = hum:LoadAnimation(animation)
- enabled = false
- wait(.01)
- animTrack:Play()
- remoteFunction:InvokeServer("Fire Arcane Ball", target)
- enabled = true
- animTrack:Stop()
- end
- local distance
- if not my_target or my_target == nil then my_target = nil end
- UIS.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton2 then
- my_target = Find_Obj()
- if my_target ~= nil then
- attacking = true
- else
- attacking = false
- end
- end_p = mouse.Hit.p
- moving = true
- while wait() do
- -----------------Move-----------------
- hum.WalkSpeed = char.Speed.Value
- if moving == true then
- stop_start_moving(false, true)
- if my_target then
- path = nil
- waypoints = nil
- path = PathFindingService:FindPathAsync(char.UpperTorso.Position, my_target.Position)
- waypoints = path:GetWaypoints()
- for _, waypoint in pairs(waypoints) do
- char.Humanoid:MoveTo(waypoint.Position)
- repeat
- distance = (waypoint.Position - char.HumanoidRootPart.Position).magnitude
- wait()
- until
- distance <= 5
- end
- else
- path = nil
- waypoints = nil
- path = PathFindingService:FindPathAsync(char.UpperTorso.Position, end_p)
- waypoints = path:GetWaypoints()
- for _, waypoint in pairs(waypoints) do
- repeat
- char.Humanoid:MoveTo(waypoint.Position)
- distance = (waypoint.Position - char.HumanoidRootPart.Position).magnitude
- wait()
- until
- distance <= 5
- end
- end
- moving = false
- end
- -----------------Attack-----------------
- if attacking == true then
- if moving == false then
- if my_target then
- if distance_to_object(my_target) < 30 then
- print("agh")
- stop_start_moving(true, false)
- onKeyPress(my_target)
- if my_target.Parent.Humanoid.Health == 0 then
- attacking = false
- end
- end
- end
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement