Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- --------------------------------
- INSTRUCTION:
- 1.create Script inside part in workspace
- 2.put this code in script
- 3.run!
- --------------------------------
- SOCIAL/ADS:
- --------------------------------
- my YouTube channel:
- https://www.youtube.com/channel/UC9mjJnPdd0aUqc_sHF2U_Tg
- my profile on Roblox:
- https://www.roblox.com/users/140427102/profile
- --------------------------------
- Enjoy guys!
- --]]
- -- Variables settings
- local klocek = script.Parent -- change path of part in Workspace
- local max_distance = 30 -- max distance of range part to see humanoid(player) object
- local speed = 0.33 -- change it (what speed of functions are to be performed)
- local speedPart = 12 -- speed of part
- local DamagePart = 6 -- damage of part
- local startedPosition = klocek.Position -- variable storage first position of part so we can returned the started postion later
- local isAttacking = false -- if part attacking player so does not attack other opponents
- --------------------------
- local function ReturnToStart()
- isAttacking = false
- local distanceToStart = (klocek.Position - startedPosition).Magnitude
- while distanceToStart >= 0.9 do
- distanceToStart = (klocek.Position - startedPosition).Magnitude
- klocek.CFrame = CFrame.new(klocek.Position,startedPosition)
- klocek.Velocity = klocek.CFrame.LookVector * speedPart
- wait(speed)
- end
- end
- -- this function search in workspace (model, humanoid and upperTorso) of players if not exists return nil
- local function SearchPlayer()
- for _,v in pairs(workspace:GetChildren()) do
- if v and v:IsA("Model") and v:FindFirstChild("Humanoid") then
- if v.Humanoid.Health >= 1 then
- local torso = v:FindFirstChild("UpperTorso")
- local humanoid = v.Humanoid
- local Distance = (torso.Position - klocek.Position).Magnitude
- if Distance > max_distance then
- continue
- end
- if torso then
- isAttacking = true
- return torso,humanoid
- else
- -- if humanoid don't have torso we return nil
- return nil
- end
- else
- -- if humanoid health have smaller health than 1 return nil
- return nil
- end
- end
- end
- -- if humanoid with model of player doesn't exists in workspace we return nil
- return nil
- end
- local function MovePart(part)
- local torso,humanoid = SearchPlayer()
- local distanceToStart = (klocek.Position - startedPosition).Magnitude
- if not torso and distanceToStart >= 0.9 then
- return ReturnToStart()
- end
- if torso then
- local Distance = (torso.Position - klocek.Position).Magnitude
- if Distance <= max_distance then
- klocek.CFrame = CFrame.new(klocek.Position,torso.Position)
- klocek.Velocity = klocek.CFrame.LookVector * speedPart
- if Distance <= 3.5 then
- humanoid.Health -= DamagePart
- end
- elseif Distance > max_distance and distanceToStart >= 0.9 then
- return ReturnToStart()
- end
- end
- end
- while true do
- MovePart(klocek)
- wait(speed)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement