Advertisement
HowToRoblox

AimTrainerScript

Mar 25th, 2022
4,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. local box = workspace:WaitForChild("TargetBox")
  2. local startButton = box:WaitForChild("AimTrainerGui"):WaitForChild("StartButton")
  3.  
  4. local camera = workspace.CurrentCamera
  5.  
  6. local currentClicked = 0
  7. local currentHit = 0
  8. local currentScore = 0
  9.  
  10. local started = false
  11.  
  12. local length = 60
  13. local speed = 1
  14.  
  15. local mouse = game.Players.LocalPlayer:GetMouse()
  16.  
  17.  
  18. mouse.Button1Down:Connect(function()
  19.    
  20.     if started then
  21.        
  22.         script.ClickSound:Play()
  23.        
  24.         currentClicked += 1
  25.        
  26.         local raycastParams = RaycastParams.new()
  27.         raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
  28.         raycastParams.FilterDescendantsInstances = {workspace.Targets}
  29.        
  30.         local rayResult = workspace:Raycast(camera.CFrame.Position, camera.CFrame.LookVector * 1000, raycastParams)
  31.        
  32.         if rayResult and rayResult.Instance then
  33.            
  34.             script.HitSound:Play()
  35.  
  36.             rayResult.Instance:Destroy()
  37.             currentHit += 1
  38.            
  39.             currentScore += 100
  40.            
  41.             box.AimTrainerGui.Points.Text = currentScore
  42.         end
  43.        
  44.         local accuracy = math.floor(currentHit / currentClicked * 100 + 0.5) or 0
  45.         box.AimTrainerGui.Accuracy.Text = accuracy .. "%"
  46.     end
  47. end)
  48.  
  49.  
  50. startButton.MouseButton1Click:Connect(function()
  51.  
  52.     if started then return end
  53.    
  54.     started = true
  55.    
  56.     game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
  57.    
  58.     local startTime = os.time()
  59.     local currentTime = startTime
  60.    
  61.     currentClicked = 0
  62.     currentHit = 0
  63.     currentScore = 0
  64.    
  65.     camera.CameraSubject = box.CameraPart
  66.     game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
  67.    
  68.     local targetsContainer = Instance.new("Model", workspace)
  69.     targetsContainer.Name = "Targets"
  70.  
  71.    
  72.     while currentTime - startTime <= length do
  73.  
  74.         local target = script.Target:Clone()
  75.         local size = math.random(2, 7)
  76.         target.Size = Vector3.new(size, size, size)
  77.         target.Position = Vector3.new(
  78.             math.random(box.Position.X - box.Size.X/2, box.Position.X + box.Size.X/2),
  79.             math.random(box.Position.Y - box.Size.Y/2, box.Position.Y + box.Size.Y/2),
  80.             math.random(box.Position.Z - box.Size.Z/2, box.Position.Z + box.Size.Z/2)
  81.         )
  82.  
  83.         target.Parent = targetsContainer
  84.  
  85.         wait(speed)
  86.  
  87.         if target then
  88.             target:Destroy()
  89.             currentScore = math.clamp(currentScore - 10, 0, math.huge)
  90.             box.AimTrainerGui.Points.Text = currentScore
  91.         end
  92.        
  93.         currentTime = os.time()
  94.        
  95.        
  96.         local timeSeconds = math.clamp(length - (currentTime - startTime), 0, math.huge)
  97.         local mins = math.floor(timeSeconds / 60)
  98.         local secs = tostring(timeSeconds % 60)
  99.         if string.len(secs) < 2 then secs = "0" .. secs end
  100.        
  101.         box.AimTrainerGui.Time.Text = mins .. ":" .. secs
  102.     end
  103.    
  104.     targetsContainer:Destroy()
  105.     game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
  106.     camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
  107.     game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
  108.     started = false
  109. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement