How to fix roblox script i get kicked after like 1 minute because invalid poistion
Archiviert a year ago
1
x
Verified
-- Wait for the game to load
if not game:IsLoaded() then
game.Loaded:Wait()
end
-- GUI settings
local Player = game.Players.LocalPlayer
local CoreGui = game.CoreGui
-- Create the GUI
local MainGui = Instance.new("ScreenGui", CoreGui)
local MainFrame = Instance.new("Frame", MainGui)
MainFrame.Size = UDim2.new(0.2, 0, 0.4, 0)
MainFrame.Position = UDim2.new(0.4, 0, 0.3, 0)
MainFrame.BackgroundColor3 = Color3.new(0, 0, 0) -- Black
MainFrame.Active = true
MainFrame.Draggable = true
-- Create buttons
local StartAutofarmButton = Instance.new("TextButton", MainFrame)
StartAutofarmButton.Size = UDim2.new(1, 0, 0.2, 0)
StartAutofarmButton.Position = UDim2.new(0, 0, 0.1, 0)
StartAutofarmButton.Text = "Start Autofarm"
StartAutofarmButton.BackgroundColor3 = Color3.new(0, 0.5, 0) -- Green background
-- Variables
local AutofarmStarted = false
local AutofarmDelay = 0.01 -- Reduces the wait time between teleports
local TweenService = game:GetService("TweenService")
-- Function for teleporting with tweening
local function PcallTP(Position)
if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
local humanoidRootPart = Player.Character.HumanoidRootPart
-- Create tween info
local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local goal = {CFrame = Position}
-- Create the tween
local tween = TweenService:Create(humanoidRootPart, tweenInfo, goal)
-- Play the tween
tween:Play()
tween.Completed:Wait() -- Wait until the tween is completed
end
end
-- Autofarm function
local function StartAutofarm()
AutofarmStarted = true
while AutofarmStarted do
local coinContainer = workspace:FindFirstChild("Normal") and workspace.Normal:FindFirstChild("CoinContainer")
if coinContainer then
for _, coin in pairs(coinContainer:GetChildren()) do
if coin:GetAttribute("CoinID") == "Coin" then -- Or "BeachBall" depending on the need
PcallTP(coin.CFrame)
wait(0.01) -- Short pause between teleports
break -- Stop the loop after teleporting to the first coin
end
end
end
wait(AutofarmDelay) -- Wait between teleports
end
end
-- Start Autofarm Button
StartAutofarmButton.MouseButton1Click:Connect(function()
if not AutofarmStarted then
StartAutofarm()
StartAutofarmButton.Text = "Stop Autofarm"
else
AutofarmStarted = false
StartAutofarmButton.Text = "Start Autofarm"
end
end)
