Advertisement
suramraja1

random

Dec 29th, 2024 (edited)
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.62 KB | None | 0 0
  1. --teleport to coin v.01 testing on vps2
  2. --fix Random Target Coin
  3. if not game:IsLoaded() then
  4.     game.Loaded:Wait()
  5. end
  6.  
  7. task.wait(10)
  8.  
  9. -- Disable collision for all BaseParts in the character
  10. task.spawn(function()
  11.     task.wait(10)
  12.     while true do
  13.         pcall(function()
  14.             for _, v in pairs(game.Players.LocalPlayer.Character:GetDescendants()) do
  15.                 if v:IsA("BasePart") and v.CanCollide == true then
  16.                     v.CanCollide = false
  17.                 end
  18.             end
  19.         end)
  20.         game:GetService("RunService").Stepped:Wait()
  21.     end
  22. end)
  23.  
  24. task.spawn(function()
  25.     task.wait(30)
  26.     firesignal(game:GetService("Players").LocalPlayer.PlayerGui.MainGUI.Game.Leaderboard.Container.Close.Toggle.MouseButton1Click)
  27. end)
  28.  
  29. task.spawn(function()
  30.     task.wait(30)
  31.     -- Create GUI elements
  32.     local coreGui = game:GetService("CoreGui")
  33.  
  34.     -- Check if GUI already exists (to avoid duplicates)
  35.     local existingGui = coreGui:FindFirstChild("CountdownGui")
  36.     if existingGui then
  37.         existingGui:Destroy()
  38.     end
  39.  
  40.     local screenGui = Instance.new("ScreenGui")
  41.     screenGui.Name = "CountdownGui"
  42.     screenGui.Parent = coreGui
  43.  
  44.     local timerLabel = Instance.new("TextLabel", screenGui)
  45.     timerLabel.Name = "TimerLabel"
  46.     timerLabel.Size = UDim2.new(0.2, 0, 0.15, 0) -- Adjust size
  47.     timerLabel.Position = UDim2.new(0.4, 0, -0.05, 0) -- Adjust position
  48.     timerLabel.BackgroundColor3 = Color3.new(0, 0, 0) -- Black background
  49.     timerLabel.TextColor3 = Color3.new(1, 1, 1) -- White text
  50.     timerLabel.TextScaled = true
  51.     timerLabel.Font = Enum.Font.SourceSansBold
  52.     timerLabel.Text = "Waiting..."
  53.  
  54.     -- Timer connection
  55.     local timerPart = game:GetService("Workspace"):FindFirstChild("RoundTimerPart")
  56.  
  57.     if timerPart and timerPart:FindFirstChild("SurfaceGui") and timerPart.SurfaceGui:FindFirstChild("Timer") then
  58.         local timerText = timerPart.SurfaceGui.Timer
  59.         timerText:GetPropertyChangedSignal("Text"):Connect(function()
  60.             timerLabel.Text = timerText.Text
  61.         end)
  62.     else
  63.         timerLabel.Text = "Timer not found"
  64.     end
  65. end)
  66.  
  67. local player = game.Players.LocalPlayer
  68. local character = player.Character or player.CharacterAdded:Wait()
  69. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  70.  
  71. -- Function to create a platform under the player's feet with adjustable size
  72. local function createPlatform()
  73.     -- Check if platform already exists
  74.     local existingPlatform = workspace:FindFirstChild("Papan")
  75.     if existingPlatform then
  76.         return existingPlatform
  77.     end
  78.  
  79.     -- Create a new part (the platform)
  80.     local platform = Instance.new("Part")
  81.     platform.Size = Vector3.new(5, 0.2, 5) -- Bigger platform with smaller height
  82.     platform.Anchored = true
  83.     platform.CanCollide = true
  84.     platform.Material = Enum.Material.SmoothPlastic
  85.     platform.Color = Color3.new(1, 1, 1) -- White platform
  86.     platform.Name = "Papan" -- Renamed to "Papan"
  87.  
  88.     -- Set the platform's position to the custom CFrame
  89.     local randomX = math.random(-100, -50) -- Adjust range as needed
  90.     local randomZ = math.random(-150, -100) -- Adjust range as needed
  91.     platform.CFrame = CFrame.new(randomX, -180, randomZ)
  92.  
  93.     -- Parent the platform to the workspace
  94.     platform.Parent = workspace
  95.     return platform
  96. end
  97.  
  98. -- Ensure the platform is always created and in position
  99. task.spawn(function()
  100.     while true do
  101.         createPlatform()
  102.         task.wait(1) -- Check every second to ensure the platform is present
  103.     end
  104. end)
  105.  
  106. -- Function to teleport player on top of the platform
  107. local function teleportToPlatform()
  108.     local platform = workspace:FindFirstChild("Papan")
  109.     if not platform then
  110.         platform = createPlatform()
  111.     end
  112.     if humanoidRootPart then
  113.         -- Adjust Y offset to place the player above the platform
  114.         local yOffset = platform.Size.Y / 2 + humanoidRootPart.Size.Y / 2 + 4 -- 4 is the additional height above the platform
  115.         humanoidRootPart.CFrame = platform.CFrame + Vector3.new(0, yOffset, 0)
  116.     end
  117. end
  118.  
  119. -- Function to tween the player using BodyVelocity and CFrame
  120. local function tweenWithBodyVelocity(targetCFrame)
  121.     local bodyVelocity = humanoidRootPart:FindFirstChild("BodyVelocity")
  122.     if not bodyVelocity then
  123.         bodyVelocity = Instance.new("BodyVelocity")
  124.         bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  125.         bodyVelocity.P = 1250
  126.         bodyVelocity.Velocity = Vector3.zero
  127.         bodyVelocity.Parent = humanoidRootPart
  128.     end
  129.  
  130.     local duration = 0.2 -- Tween duration
  131.     local startTime = tick()
  132.     local startCFrame = humanoidRootPart.CFrame
  133.     local elapsedTime = 0
  134.  
  135.     while elapsedTime < duration do
  136.         elapsedTime = tick() - startTime
  137.         local alpha = elapsedTime / duration
  138.         local currentCFrame = startCFrame:Lerp(targetCFrame, alpha)
  139.  
  140.         local velocity = (currentCFrame.Position - humanoidRootPart.Position).Unit * 25 -- Adjust speed
  141.         bodyVelocity.Velocity = velocity
  142.  
  143.         humanoidRootPart.CFrame = currentCFrame
  144.         task.wait(0.01)
  145.     end
  146.  
  147.     -- Stop movement
  148.     bodyVelocity.Velocity = Vector3.zero
  149.     bodyVelocity:Destroy()
  150.  
  151.     -- Snap to the final target position
  152.     humanoidRootPart.CFrame = targetCFrame
  153. end
  154.  
  155. local function resetAutofarm()
  156.     isCollectingCoin = false
  157.     if AutofarmIN and AutofarmStarted and not RoundEnded then
  158.         teleportToPlatform()
  159.     end
  160. end
  161.  
  162. local isCollectingCoin = false
  163. local RoundEnded = false
  164.  
  165. player.CharacterAdded:Connect(function(newCharacter)
  166.     character = newCharacter
  167.     humanoidRootPart = newCharacter:WaitForChild("HumanoidRootPart")
  168.     resetAutofarm()
  169. end)
  170.  
  171. SettingsAutofarm = _G.AutofarmSettings or {AntiAfk = true, ResetWhenFullBag = true}
  172. _G.AutofarmSettings = SettingsAutofarm
  173. if _G.AutoFarmMM2IsLoaded then return end
  174. _G.AutoFarmMM2IsLoaded = true
  175.  
  176. local Player = game.Players.LocalPlayer
  177. local Players = game.Players
  178. local RunService = game:GetService("RunService")
  179. local TweenService = game:GetService("TweenService")
  180.  
  181. local CoinCollectedEvent = game.ReplicatedStorage.Remotes.Gameplay.CoinCollected
  182. local RoundStartEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundStart
  183. local RoundEndEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundEndFade
  184. local autofarmstopevent = Instance.new("BindableEvent")
  185.  
  186. local function AntiAFK()
  187.     local GC = getconnections or get_signal_cons
  188.     if GC then
  189.         for _, v in pairs(GC(Player.Idled)) do
  190.             if v["Disable"] then
  191.                 v["Disable"](v)
  192.             elseif v["Disconnect"] then
  193.                 v["Disconnect"](v)
  194.             end
  195.         end
  196.     else
  197.         local VirtualUser = cloneref(game:GetService("VirtualUser"))
  198.         Players.LocalPlayer.Idled:Connect(function()
  199.             VirtualUser:CaptureController()
  200.             VirtualUser:ClickButton2(Vector2.new())
  201.         end)
  202.     end
  203. end
  204.  
  205. local ResetWhenFullBag = SettingsAutofarm.ResetWhenFullBag
  206. local AutofarmIN = false
  207. local AutofarmStarted = true
  208. local CurrentCoinType = "SnowToken"
  209.  
  210. local function returncoincontainer()
  211.     for _, v in workspace:GetChildren() do
  212.         if v:FindFirstChild("CoinContainer") and v:IsA("Model") then
  213.             return v:FindFirstChild("CoinContainer")
  214.         end
  215.     end
  216.     return false
  217. end
  218.  
  219. local function getRandomCoin(container)
  220.     local coins = container:GetChildren()
  221.     -- Shuffle the coins to randomize selection
  222.     for i = #coins, 2, -1 do
  223.         local j = math.random(1, i)
  224.         coins[i], coins[j] = coins[j], coins[i]
  225.     end
  226.  
  227.     for _, coin in ipairs(coins) do
  228.         if coin:FindFirstChild("TouchInterest") then
  229.             return coin
  230.         end
  231.     end
  232.     return nil
  233. end
  234.  
  235. local function StayOnPlatform()
  236.     if not isCollectingCoin then
  237.         teleportToPlatform()
  238.         task.wait(0.7 + math.random() * 0.1)
  239.     end
  240. end
  241.  
  242. task.spawn(function()
  243.     while true do
  244.         if AutofarmStarted and AutofarmIN and Player.Character and returncoincontainer() then
  245.             -- Step 1: Stay on the platform
  246.             StayOnPlatform()
  247.  
  248.             -- Step 2: Move to random coin with TouchInterest
  249.             local coinContainer = returncoincontainer()
  250.             if coinContainer then
  251.                 isCollectingCoin = true
  252.                 local coin = getRandomCoin(coinContainer)
  253.                 if coin then
  254.                     -- Tween to target position using BodyVelocity and CFrame
  255.                     tweenWithBodyVelocity(coin.CFrame)
  256.  
  257.                     -- Fire touch interest to collect the coin
  258.                     pcall(function()
  259.                         firetouchinterest(Player.Character.HumanoidRootPart, coin, 0)
  260.                         task.wait(0.01)
  261.                     end)
  262.  
  263.                     -- Wait until the coin is collected or gone
  264.                     while coin.Parent == coinContainer and coin:FindFirstChild("TouchInterest") do
  265.                         task.wait(0.1)
  266.                     end
  267.                     -- Wait before returning to platform
  268.                     task.wait(0.2 + math.random() * 0.4)
  269.                 end
  270.  
  271.                 -- Step 3: Return to platform
  272.                 isCollectingCoin = false
  273.                 if AutofarmIN and AutofarmStarted and not RoundEnded then
  274.                     StayOnPlatform()
  275.                 end
  276.             end
  277.         else
  278.             task.wait(0.1)
  279.         end
  280.         task.wait(0.05)
  281.     end
  282. end)
  283.  
  284. CoinCollectedEvent.OnClientEvent:Connect(function(cointype, current, max)
  285.     AutofarmIN = true
  286.     if cointype == CurrentCoinType and tonumber(current) == tonumber(max) then
  287.         AutofarmIN = false
  288.         if ResetWhenFullBag then
  289.             Player.Character.Humanoid.Health = 0
  290.         end
  291.     end
  292. end)
  293.  
  294. RoundStartEvent.OnClientEvent:Connect(function()
  295.     AutofarmIN = true
  296.     RoundEnded = false
  297.     resetAutofarm()
  298.  
  299.     -- Update timer on round start
  300.     local timerPart = game:GetService("Workspace"):FindFirstChild("RoundTimerPart")
  301.     local screenGui = game:GetService("CoreGui"):FindFirstChild("CountdownGui")
  302.     if not screenGui then
  303.         screenGui = Instance.new("ScreenGui")
  304.         screenGui.Name = "CountdownGui"
  305.         screenGui.Parent = game:GetService("CoreGui")
  306.  
  307.         local timerLabel = Instance.new("TextLabel", screenGui)
  308.         timerLabel.Name = "TimerLabel"
  309.         timerLabel.Size = UDim2.new(0.2, 0, 0.15, 0)
  310.         timerLabel.Position = UDim2.new(0.4, 0, -0.05, 0)
  311.         timerLabel.BackgroundColor3 = Color3.new(0, 0, 0)
  312.         timerLabel.TextColor3 = Color3.new(1, 1, 1)
  313.         timerLabel.TextScaled = true
  314.         timerLabel.Font = Enum.Font.SourceSansBold
  315.         timerLabel.Text = "Waiting..."
  316.     end
  317.  
  318.     local timerLabel = screenGui:FindFirstChild("TimerLabel")
  319.     if timerPart and timerPart:FindFirstChild("SurfaceGui") and timerPart.SurfaceGui:FindFirstChild("Timer") then
  320.         local timerText = timerPart.SurfaceGui.Timer
  321.         timerText:GetPropertyChangedSignal("Text"):Connect(function()
  322.             if timerLabel then
  323.                 timerLabel.Text = timerText.Text
  324.             end
  325.         end)
  326.         -- Initialize label with the current timer value
  327.         if timerLabel then
  328.             timerLabel.Text = timerText.Text
  329.         end
  330.     else
  331.         if timerLabel then
  332.             timerLabel.Text = "Timer not found"
  333.         end
  334.     end
  335. end)
  336.  
  337.  
  338. RoundEndEvent.OnClientEvent:Connect(function()
  339.     AutofarmIN = false
  340.     RoundEnded = true
  341.     task.wait(1)
  342. end)
  343.  
  344. RunService.Heartbeat:Connect(function()
  345.     if AutofarmIN then
  346.         StayOnPlatform()
  347.     end
  348. end)
  349.  
  350. AntiAFK()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement