--// CLEANUP (prevents duplicates if re-executed) local player = game.Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") if playerGui:FindFirstChild("SnakeUI") then playerGui.SnakeUI:Destroy() end --// Create ScreenGui local gui = Instance.new("ScreenGui") gui.Name = "SnakeUI" gui.ResetOnSpawn = false gui.Parent = playerGui --// Main Window local window = Instance.new("Frame") window.Size = UDim2.new(0, 300, 0, 420) window.Position = UDim2.new(0.5, -150, 0.5, -210) window.BackgroundColor3 = Color3.fromRGB(240, 240, 240) window.BorderSizePixel = 2 window.Parent = gui --// Title Bar local titleBar = Instance.new("Frame", window) titleBar.Size = UDim2.new(1, 0, 0, 30) titleBar.BackgroundColor3 = Color3.fromRGB(0, 120, 215) local title = Instance.new("TextLabel", titleBar) title.Size = UDim2.new(1, 0, 1, 0) title.Text = "Snake" title.TextColor3 = Color3.new(1,1,1) title.BackgroundTransparency = 1 title.Font = Enum.Font.SourceSansBold title.TextSize = 18 --// DRAG SYSTEM (works on mobile + executors) local dragging = false local dragStart, startPos titleBar.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then dragging = true dragStart = input.Position startPos = window.Position end end) titleBar.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then dragging = false end end) game:GetService("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( startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y ) end end) --// Score Label local scoreLabel = Instance.new("TextLabel", window) scoreLabel.Position = UDim2.new(0, 10, 0, 32) scoreLabel.Size = UDim2.new(1, -20, 0, 20) scoreLabel.BackgroundTransparency = 1 scoreLabel.TextColor3 = Color3.new(0,0,0) scoreLabel.Font = Enum.Font.SourceSansBold scoreLabel.TextSize = 16 scoreLabel.Text = "Score: 0 | High: 0" --// Game Area local gameFrame = Instance.new("Frame", window) gameFrame.Position = UDim2.new(0, 10, 0, 55) gameFrame.Size = UDim2.new(1, -20, 0, 225) gameFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30) --// Controls local controls = Instance.new("Frame", window) controls.Position = UDim2.new(0, 0, 1, -140) controls.Size = UDim2.new(1, 0, 0, 140) controls.BackgroundTransparency = 1 local function makeButton(text, pos) local btn = Instance.new("TextButton", controls) btn.Size = UDim2.new(0, 60, 0, 60) btn.Position = pos btn.Text = text btn.BackgroundColor3 = Color3.fromRGB(200,200,200) btn.TextScaled = true return btn end local up = makeButton("↑", UDim2.new(0.5, -30, 0, 0)) local down = makeButton("↓", UDim2.new(0.5, -30, 0, 70)) local left = makeButton("←", UDim2.new(0.5, -100, 0, 70)) local right = makeButton("→", UDim2.new(0.5, 40, 0, 70)) --// Game Over UI local gameOverLabel = Instance.new("TextLabel", gameFrame) gameOverLabel.Size = UDim2.new(1, 0, 0, 50) gameOverLabel.Position = UDim2.new(0, 0, 0.35, 0) gameOverLabel.Text = "GAME OVER" gameOverLabel.TextColor3 = Color3.new(1,0,0) gameOverLabel.BackgroundTransparency = 1 gameOverLabel.TextScaled = true gameOverLabel.Visible = false local finalScoreLabel = Instance.new("TextLabel", gameFrame) finalScoreLabel.Size = UDim2.new(1, 0, 0, 30) finalScoreLabel.Position = UDim2.new(0, 0, 0.5, 0) finalScoreLabel.BackgroundTransparency = 1 finalScoreLabel.TextColor3 = Color3.new(1,1,1) finalScoreLabel.TextScaled = true finalScoreLabel.Visible = false local retryButton = Instance.new("TextButton", gameFrame) retryButton.Size = UDim2.new(0.5, 0, 0, 40) retryButton.Position = UDim2.new(0.25, 0, 0.65, 0) retryButton.Text = "Retry" retryButton.Visible = false --// Grid local gridSize = 15 local cellSize = 15 local cells = {} for x = 1, gridSize do for y = 1, gridSize do local cell = Instance.new("Frame", gameFrame) cell.Size = UDim2.new(0, cellSize, 0, cellSize) cell.Position = UDim2.new(0, (x-1)*cellSize, 0, (y-1)*cellSize) cell.BackgroundColor3 = Color3.fromRGB(50,50,50) cells[x..","..y] = cell end end --// Game State local snake, direction, food, alive local score = 0 local highScore = 0 local function updateScore() scoreLabel.Text = "Score: "..score.." | High: "..highScore end local function startGame() snake = {{x = 5, y = 5}} direction = "Right" food = {x = math.random(1, gridSize), y = math.random(1, gridSize)} alive = true score = 0 gameOverLabel.Visible = false retryButton.Visible = false finalScoreLabel.Visible = false updateScore() end startGame() --// Inputs up.MouseButton1Click:Connect(function() if alive then direction = "Up" end end) down.MouseButton1Click:Connect(function() if alive then direction = "Down" end end) left.MouseButton1Click:Connect(function() if alive then direction = "Left" end end) right.MouseButton1Click:Connect(function() if alive then direction = "Right" end end) retryButton.MouseButton1Click:Connect(startGame) --// Game Loop task.spawn(function() while true do task.wait(0.2) if not alive then continue end local head = {x = snake[1].x, y = snake[1].y} if direction == "Up" then head.y -= 1 end if direction == "Down" then head.y += 1 end if direction == "Left" then head.x -= 1 end if direction == "Right" then head.x += 1 end if head.x < 1 or head.y < 1 or head.x > gridSize or head.y > gridSize then alive = false end for _, part in ipairs(snake) do if head.x == part.x and head.y == part.y then alive = false end end if not alive then if score > highScore then highScore = score end gameOverLabel.Visible = true finalScoreLabel.Text = "Score: "..score finalScoreLabel.Visible = true retryButton.Visible = true updateScore() continue end table.insert(snake, 1, head) if head.x == food.x and head.y == food.y then score += 1 updateScore() food = {x = math.random(1, gridSize), y = math.random(1, gridSize)} else table.remove(snake) end for _, cell in pairs(cells) do cell.BackgroundColor3 = Color3.fromRGB(50,50,50) end for _, part in ipairs(snake) do cells[part.x..","..part.y].BackgroundColor3 = Color3.fromRGB(0,255,0) end cells[food.x..","..food.y].BackgroundColor3 = Color3.fromRGB(255,0,0) end end)