--[[ Coin Farm — tween teleport to coins ----------------------------------- How it works: 1. The character drops a bit below the map, so nobody above can see it. 2. A tween moves it under the chosen coin. 3. It rises to the coin and holds there for a moment — the coin is collected. 4. It drops back down and flies to the next one. Toggle with the window button or the K key. ]] local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local LocalPlayer = Players.LocalPlayer local CONFIG = { travelSpeed = 320, -- speed of the flight under the map, studs/sec riseSpeed = 150, -- speed of the climb to a coin, studs/sec sinkDepth = 22, -- how far below the map to sink holdTime = 0.5, -- seconds spent on a coin idleWait = 2, -- pause when there are no coins left toggleKey = Enum.KeyCode.K, } local THEME = { background = Color3.fromRGB(20, 21, 26), card = Color3.fromRGB(28, 30, 38), stroke = Color3.fromRGB(52, 56, 68), text = Color3.fromRGB(236, 237, 242), muted = Color3.fromRGB(146, 151, 165), accent = Color3.fromRGB(255, 198, 58), accentText = Color3.fromRGB(30, 24, 6), danger = Color3.fromRGB(232, 92, 92), } local state = { running = false, collected = 0, skipped = 0, status = "Ready", lastSurfacePosition = nil, } local function getCharacterParts() local character = LocalPlayer.Character if not character then return nil, nil, nil end local humanoid = character:FindFirstChildOfClass("Humanoid") local rootPart = character:FindFirstChild("HumanoidRootPart") if not humanoid or not rootPart or humanoid.Health <= 0 then return nil, nil, nil end return character, humanoid, rootPart end local function getCoinContainer() return workspace:FindFirstChild("CoinContainer") end local function isCoinGone(coin) return coin == nil or coin.Parent == nil or coin.Transparency > 0.5 end local function getAvailableCoins() local container = getCoinContainer() local coins = {} if not container then return coins end for _, model in ipairs(container:GetChildren()) do local coin = model:FindFirstChild("Coin") if coin and coin:IsA("BasePart") and not isCoinGone(coin) then table.insert(coins, coin) end end return coins end local function findNearestCoin() local _, _, rootPart = getCharacterParts() local origin = rootPart and rootPart.Position or Vector3.zero local best, bestDistance = nil, math.huge for _, coin in ipairs(getAvailableCoins()) do local position = coin.Position local delta = Vector3.new(position.X - origin.X, 0, position.Z - origin.Z) local distance = delta.Magnitude if distance < bestDistance then best, bestDistance = coin, distance end end return best end local function buildRaycastFilter() local filter = {} local character = LocalPlayer.Character if character then table.insert(filter, character) end local container = getCoinContainer() if container then table.insert(filter, container) end for _, player in ipairs(Players:GetPlayers()) do if player ~= LocalPlayer and player.Character then table.insert(filter, player.Character) end end return filter end local function getGroundHeight(position: Vector3): number local parameters = RaycastParams.new() parameters.FilterType = Enum.RaycastFilterType.Exclude parameters.FilterDescendantsInstances = buildRaycastFilter() local result = workspace:Raycast(position + Vector3.new(0, 6, 0), Vector3.new(0, -200, 0), parameters) if result then return result.Position.Y end return position.Y - 2 end local function getSurfaceHeight(position: Vector3): number local parameters = RaycastParams.new() parameters.FilterType = Enum.RaycastFilterType.Exclude parameters.FilterDescendantsInstances = buildRaycastFilter() local result = workspace:Raycast(Vector3.new(position.X, 1000, position.Z), Vector3.new(0, -1500, 0), parameters) if result then return result.Position.Y end return 650 end -- Smoothly drives the root part to a point. The root part stays anchored while -- flying, so the character cannot fall into the void or clip through the map. local function moveTo(targetPosition: Vector3, speed: number): boolean local _, _, rootPart = getCharacterParts() if not rootPart then return false end rootPart.Anchored = true local startPosition = rootPart.Position local distance = (targetPosition - startPosition).Magnitude if distance < 0.6 then return true end local horizontal = Vector3.new(targetPosition.X - startPosition.X, 0, targetPosition.Z - startPosition.Z) local rotation if horizontal.Magnitude > 2 then rotation = CFrame.lookAt(Vector3.zero, horizontal.Unit) else rotation = rootPart.CFrame - rootPart.CFrame.Position end local duration = distance / math.max(speed, 15) local elapsed = 0 local finished = false local connection = RunService.Heartbeat:Connect(function(deltaTime) if finished then return end elapsed += deltaTime local alpha = math.min(elapsed / duration, 1) local position = startPosition:Lerp(targetPosition, alpha) rootPart.CFrame = CFrame.new(position) * rotation rootPart.AssemblyLinearVelocity = Vector3.zero if alpha >= 1 then finished = true end end) while not finished do if not state.running or not rootPart.Parent then break end task.wait() end connection:Disconnect() return finished end -- Short stop on a coin. Here the root part is unanchored on purpose: -- the server only registers a coin touch for a "live" character. local function holdAtCoin(position: Vector3) local _, _, rootPart = getCharacterParts() if not rootPart then return end local rotation = rootPart.CFrame - rootPart.CFrame.Position rootPart.Anchored = false local startedAt = os.clock() local connection connection = RunService.Heartbeat:Connect(function() if os.clock() - startedAt > CONFIG.holdTime then return end local wobble = math.sin((os.clock() - startedAt) * 25) * 1.2 rootPart.CFrame = CFrame.new(position + Vector3.new(wobble, 0, 0)) * rotation rootPart.AssemblyLinearVelocity = Vector3.zero end) task.wait(CONFIG.holdTime) connection:Disconnect() if rootPart.Parent then rootPart.Anchored = true end end -- Puts the character back on the surface and unanchors it. local function releaseCharacter() local _, _, rootPart = getCharacterParts() if not rootPart then return end local position = rootPart.Position local anchorPosition = state.lastSurfacePosition local surfaceX, surfaceZ if anchorPosition then surfaceX, surfaceZ = anchorPosition.X, anchorPosition.Z else surfaceX, surfaceZ = position.X, position.Z end local groundY = getSurfaceHeight(Vector3.new(surfaceX, position.Y, surfaceZ)) rootPart.Anchored = true rootPart.CFrame = CFrame.new(Vector3.new(surfaceX, groundY + 3.2, surfaceZ)) rootPart.AssemblyLinearVelocity = Vector3.zero task.wait(0.05) if rootPart.Parent then rootPart.Anchored = false end end local setStatus local refreshCounters local refreshToggle local function collectCoin(coin): boolean local _, _, rootPart = getCharacterParts() if not rootPart then return false end local coinPosition = coin.Position local groundY = getGroundHeight(coinPosition) local underPosition = Vector3.new(coinPosition.X, groundY - CONFIG.sinkDepth, coinPosition.Z) -- 1. Sink below the map setStatus("Going under the map") local startSurfaceY = getGroundHeight(rootPart.Position) if not moveTo(Vector3.new(rootPart.Position.X, startSurfaceY - CONFIG.sinkDepth, rootPart.Position.Z), CONFIG.travelSpeed) then return false end -- 2. Tween under the coin setStatus("Flying to the coin") if not moveTo(underPosition, CONFIG.travelSpeed) then return false end -- 3. Rise to the coin setStatus("Rising to the coin") if not moveTo(coinPosition + Vector3.new(0, 1, 0), CONFIG.riseSpeed) then return false end -- 4. Collect it setStatus("Collecting coin") holdAtCoin(coinPosition + Vector3.new(0, 1, 0)) if not isCoinGone(coin) then holdAtCoin(coinPosition + Vector3.new(0, 2.5, 0)) end state.lastSurfacePosition = Vector3.new(coinPosition.X, coinPosition.Y, coinPosition.Z) return isCoinGone(coin) end local function farmLoop() while state.running do local character, humanoid = getCharacterParts() if not character or not humanoid then setStatus("Character lost — stopped") break end local coin = findNearestCoin() if not coin then setStatus("Waiting for coin respawn") task.wait(CONFIG.idleWait) continue end if collectCoin(coin) then state.collected += 1 else state.skipped += 1 end refreshCounters() end end local gui local statusLabel local counterLabel local toggleButton local function make(className, properties, parent) local instance = Instance.new(className) for key, value in pairs(properties) do instance[key] = value end if parent then instance.Parent = parent end return instance end refreshCounters = function() if counterLabel then counterLabel.Text = string.format("Collected: %d · Skipped: %d", state.collected, state.skipped) end end setStatus = function(text: string) state.status = text if statusLabel then statusLabel.Text = text end end refreshToggle = function() if not toggleButton then return end if state.running then toggleButton.Text = "Stop · K" toggleButton.BackgroundColor3 = THEME.danger toggleButton.TextColor3 = Color3.fromRGB(255, 245, 245) else toggleButton.Text = "Start · K" toggleButton.BackgroundColor3 = THEME.accent toggleButton.TextColor3 = THEME.accentText end end local function addSetting(parentFrame, labelText: string, value: number, offsetX: number, onApply) make("TextLabel", { Position = UDim2.new(0, offsetX, 0, 140), Size = UDim2.fromOffset(60, 12), BackgroundTransparency = 1, Font = Enum.Font.GothamMedium, Text = labelText, TextSize = 10, TextColor3 = THEME.muted, TextXAlignment = Enum.TextXAlignment.Left, }, parentFrame) local box = make("TextBox", { Position = UDim2.new(0, offsetX, 0, 154), Size = UDim2.fromOffset(60, 22), BackgroundColor3 = THEME.card, BorderSizePixel = 0, Font = Enum.Font.GothamMedium, Text = tostring(value), TextSize = 12, TextColor3 = THEME.text, ClearTextOnFocus = false, }, parentFrame) make("UICorner", { CornerRadius = UDim.new(0, 6) }, box) make("UIStroke", { Color = THEME.stroke, Thickness = 1, Transparency = 0.2 }, box) box.FocusLost:Connect(function() local parsed = tonumber(box.Text) local applied = parsed and onApply(parsed) or nil box.Text = tostring(applied or value) end) end local startFarm local stopFarm local function buildGui() local playerGui = LocalPlayer:WaitForChild("PlayerGui") local old = playerGui:FindFirstChild("CoinFarmGui") if old then old:Destroy() end gui = make("ScreenGui", { Name = "CoinFarmGui", ResetOnSpawn = false, IgnoreGuiInset = true, ZIndexBehavior = Enum.ZIndexBehavior.Sibling, DisplayOrder = 50, }, playerGui) local window = make("Frame", { Name = "Window", Size = UDim2.fromOffset(236, 190), Position = UDim2.new(0.5, 0, 0.5, 0), AnchorPoint = Vector2.new(0.5, 0.5), BackgroundColor3 = THEME.background, BorderSizePixel = 0, Active = true, }, gui) make("UICorner", { CornerRadius = UDim.new(0, 12) }, window) make("UIStroke", { Color = THEME.stroke, Thickness = 1, Transparency = 0.15 }, window) local header = make("Frame", { Name = "Header", Size = UDim2.new(1, 0, 0, 34), BackgroundColor3 = THEME.card, BorderSizePixel = 0, }, window) make("UICorner", { CornerRadius = UDim.new(0, 12) }, header) make("Frame", { Size = UDim2.new(1, 0, 0, 14), Position = UDim2.new(0, 0, 1, -14), BackgroundColor3 = THEME.card, BorderSizePixel = 0, }, header) make("TextLabel", { Position = UDim2.new(0, 14, 0, 0), Size = UDim2.new(1, -50, 1, 0), BackgroundTransparency = 1, Font = Enum.Font.GothamBold, Text = "Coin Farm", TextSize = 15, TextColor3 = THEME.text, TextXAlignment = Enum.TextXAlignment.Left, }, header) local closeButton = make("TextButton", { Size = UDim2.fromOffset(26, 26), Position = UDim2.new(1, -32, 0, 4), BackgroundTransparency = 1, Font = Enum.Font.GothamBold, Text = "×", TextSize = 18, TextColor3 = THEME.muted, }, header) closeButton.MouseEnter:Connect(function() closeButton.TextColor3 = THEME.text end) closeButton.MouseLeave:Connect(function() closeButton.TextColor3 = THEME.muted end) closeButton.MouseButton1Click:Connect(function() stopFarm() if gui then gui:Destroy() end end) statusLabel = make("TextLabel", { Position = UDim2.new(0, 14, 0, 46), Size = UDim2.new(1, -28, 0, 16), BackgroundTransparency = 1, Font = Enum.Font.GothamMedium, Text = state.status, TextSize = 12, TextColor3 = THEME.muted, TextXAlignment = Enum.TextXAlignment.Left, }, window) counterLabel = make("TextLabel", { Position = UDim2.new(0, 14, 0, 66), Size = UDim2.new(1, -28, 0, 16), BackgroundTransparency = 1, Font = Enum.Font.GothamBold, Text = "Collected: 0 · Skipped: 0", TextSize = 12, TextColor3 = THEME.text, TextXAlignment = Enum.TextXAlignment.Left, }, window) toggleButton = make("TextButton", { Position = UDim2.new(0, 14, 0, 92), Size = UDim2.new(1, -28, 0, 38), BackgroundColor3 = THEME.accent, BorderSizePixel = 0, Font = Enum.Font.GothamBold, Text = "Start · K", TextSize = 14, TextColor3 = THEME.accentText, AutoButtonColor = true, }, window) make("UICorner", { CornerRadius = UDim.new(0, 9) }, toggleButton) toggleButton.MouseButton1Click:Connect(function() if state.running then stopFarm() else startFarm() end end) addSetting(window, "Depth", CONFIG.sinkDepth, 14, function(value) CONFIG.sinkDepth = math.clamp(value, 5, 80) return CONFIG.sinkDepth end) addSetting(window, "Speed", CONFIG.travelSpeed, 88, function(value) CONFIG.travelSpeed = math.clamp(value, 60, 900) return CONFIG.travelSpeed end) addSetting(window, "Climb", CONFIG.riseSpeed, 162, function(value) CONFIG.riseSpeed = math.clamp(value, 40, 600) return CONFIG.riseSpeed end) -- Window dragging local dragging = false local dragStart local startPosition header.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then dragging = true dragStart = input.Position startPosition = window.Position input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then dragging = false end end) end end) UserInputService.InputChanged:Connect(function(input) if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then local delta = input.Position - dragStart window.Position = UDim2.new( startPosition.X.Scale, startPosition.X.Offset + delta.X, startPosition.Y.Scale, startPosition.Y.Offset + delta.Y ) end end) end startFarm = function() if state.running then return end local _, _, rootPart = getCharacterParts() if not rootPart then setStatus("Character not loaded") return end state.running = true state.collected = 0 state.skipped = 0 state.lastSurfacePosition = nil refreshCounters() refreshToggle() setStatus("Starting") task.spawn(function() local ok, err = pcall(farmLoop) state.running = false releaseCharacter() refreshToggle() if ok then setStatus("Ready") else setStatus("Error: " .. tostring(err)) end end) end stopFarm = function() if not state.running then return end state.running = false setStatus("Stopping") task.delay(0.25, function() releaseCharacter() refreshToggle() setStatus("Ready") end) end if _G.CoinFarm and _G.CoinFarm.stop then pcall(_G.CoinFarm.stop) end buildGui() refreshToggle() refreshCounters() UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == CONFIG.toggleKey then if state.running then stopFarm() else startFarm() end end end) LocalPlayer.CharacterAdded:Connect(function() if state.running then state.running = false refreshToggle() setStatus("Character died — stopped") end end) _G.CoinFarm = { start = startFarm, stop = stopFarm, config = CONFIG, state = state, } setStatus("Ready") print("[CoinFarm] loaded")