-- Full Pac-Man GUI with unreachable pellet workaround -- Place in StarterPlayerScripts local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer local guiParent = player:WaitForChild("PlayerGui") -- === GUI === local screenGui = Instance.new("ScreenGui") screenGui.Name = "PacManGame" screenGui.ResetOnSpawn = false screenGui.Parent = guiParent local mainFrame = Instance.new("Frame") mainFrame.Size = UDim2.new(0, 800, 0, 672) mainFrame.Position = UDim2.new(0.5, -400, 0.5, -336) mainFrame.BackgroundColor3 = Color3.fromRGB(10,10,40) mainFrame.BorderSizePixel = 2 mainFrame.Parent = screenGui local scoreLabel = Instance.new("TextLabel") scoreLabel.Size = UDim2.new(1,0,0,30) scoreLabel.Position = UDim2.new(0,0,0,-30) scoreLabel.BackgroundTransparency = 1 scoreLabel.Text = "Score: 0" scoreLabel.Font = Enum.Font.SourceSansBold scoreLabel.TextSize = 22 scoreLabel.TextColor3 = Color3.new(1,1,1) scoreLabel.Parent = mainFrame -- === Fixed Map === local map = { "1111111111111111111111111", "1000001000001000001000001", "1011111011111111111011101", "1000000000001000000000001", "1011110111101011110111101", "1000000000000000000000001", "1011111011111111111011101", "1000001000000P0000010001", "1111101110111011101111111", "1000001000000000000010001", "1011111111111111111111101", "1000000000000000000000001", "1011111011111111111011101", "1000001000000000000010001", "1111101110111011101111111", "1000000000000000000000001", "1011110111101011110111101", "1000000000001000000000001", "1011110111101011110111101", "1000001000001000001000001", "1111111111111111111111111", } local rows = #map local cols = #map[1] local CELL = 32 local dirs = {Up={dr=-1,dc=0}, Down={dr=1,dc=0}, Left={dr=0,dc=-1}, Right={dr=0,dc=1}} -- === Maze, Pellets, Player, Ghost Positions === local pellets = {} local pelletFrames = {} local pelletCount = 0 local playerPos = {r=0,c=0} local ghostPositions = {} for r=1,rows do for c=1,cols do local cell = map[r]:sub(c,c) local x = (c-1)*CELL local y = (r-1)*CELL if cell=="1" then local wall = Instance.new("Frame") wall.Size = UDim2.new(0,CELL,0,CELL) wall.Position = UDim2.new(0,x,0,y) wall.BackgroundColor3 = Color3.fromRGB(20,20,200) wall.BorderSizePixel = 0 wall.Parent = mainFrame elseif cell=="0" then pellets[r..","..c] = true pelletCount +=1 local dot = Instance.new("Frame") dot.Size = UDim2.new(0,6,0,6) dot.Position = UDim2.new(0,x+(CELL/2-3),0,y+(CELL/2-3)) dot.BackgroundColor3 = Color3.fromRGB(255,255,255) dot.BorderSizePixel = 0 dot.Parent = mainFrame pelletFrames[r..","..c] = dot elseif cell=="P" then playerPos={r=r,c=c} end end end if playerPos.r==0 then playerPos={r=2,c=2} end -- === Random Ghost Spawns === local openCells = {} for r=1,rows do for c=1,cols do if map[r]:sub(c,c)=="0" then table.insert(openCells,{r=r,c=c}) end end end for i=1,4 do if #openCells==0 then break end local index = math.random(1,#openCells) table.insert(ghostPositions,openCells[index]) table.remove(openCells,index) end -- === Player === local pac = Instance.new("Frame") pac.Size = UDim2.new(0,CELL-4,0,CELL-4) pac.BackgroundColor3 = Color3.fromRGB(255,255,0) pac.Position = UDim2.new(0,(playerPos.c-1)*CELL+2,0,(playerPos.r-1)*CELL+2) pac.Parent = mainFrame -- === Ghosts === local ghosts = {} local ghostColors = {Color3.fromRGB(255,0,0),Color3.fromRGB(255,184,255),Color3.fromRGB(0,255,255),Color3.fromRGB(255,184,82)} for i=1,#ghostPositions do local ghost = Instance.new("Frame") ghost.Size = UDim2.new(0,CELL-4,0,CELL-4) ghost.BackgroundColor3 = ghostColors[i] or Color3.fromRGB(255,0,0) ghost.Position = UDim2.new(0,(ghostPositions[i].c-1)*CELL+2,0,(ghostPositions[i].r-1)*CELL+2) ghost.Parent = mainFrame table.insert(ghosts,{gui=ghost,pos={r=ghostPositions[i].r,c=ghostPositions[i].c},dir={dr=0,dc=0}}) end -- === Blocked pellets positions to ignore for win === local blockedPellets = { "8,23", "9,23", "10,23" -- adjust if needed to match exact unreachable dots } -- === Game State === local running = true local gameEnded = false local score = 0 local currentDir = nil local renderConn, inputConn local mobileConns = {} local function canMove(r,c) return r>=1 and r<=rows and c>=1 and c<=cols and map[r]:sub(c,c)~="1" end local function movePlayer(r,c) playerPos={r=r,c=c} pac.Position = UDim2.new(0,(c-1)*CELL+2,0,(r-1)*CELL+2) local key=r..","..c if pellets[key] then pellets[key]=nil score +=1 scoreLabel.Text = "Score: "..score if pelletFrames[key] then pelletFrames[key]:Destroy() end pelletCount -=1 end end local function ghostChooseDir(g) local possible = {} for _,d in pairs(dirs) do local nr,nc=g.pos.r+d.dr,g.pos.c+d.dc if canMove(nr,nc) and not (g.dir.dr==-d.dr and g.dir.dc==-d.dc) then table.insert(possible,d) end end if #possible==0 then for _,d in pairs(dirs) do local nr,nc=g.pos.r+d.dr,g.pos.c+d.dc if canMove(nr,nc) then table.insert(possible,d) end end end if #possible>0 then table.sort(possible,function(a,b) local da = math.abs((g.pos.r+a.dr)-playerPos.r) + math.abs((g.pos.c+a.dc)-playerPos.c) local db = math.abs((g.pos.r+b.dr)-playerPos.r) + math.abs((g.pos.c+b.dc)-playerPos.c) return da0.15 and currentDir then local nr,nc=playerPos.r+currentDir.dr,playerPos.c+currentDir.dc if canMove(nr,nc) then movePlayer(nr,nc) end playerTimer=0 end -- Ghost movement if ghostTimer>0.3 then for _,g in ipairs(ghosts) do ghostChooseDir(g) local nr,nc=g.pos.r+g.dir.dr,g.pos.c+g.dir.dc if canMove(nr,nc) then g.pos={r=nr,c=nc} g.gui.Position=UDim2.new(0,(nc-1)*CELL+2,0,(nr-1)*CELL+2) end end ghostTimer=0 end -- Collision for _,g in ipairs(ghosts) do if g.pos.r==playerPos.r and g.pos.c==playerPos.c and not gameEnded then gameEnded=true running=false showEndGame("💀 Game Over!\nScore: "..score) return end end -- Win condition ignoring blocked pellets local remainingPellets = 0 for k,v in pairs(pellets) do local blocked = false for _,b in ipairs(blockedPellets) do if k==b then blocked=true break end end if not blocked then remainingPellets +=1 end end if remainingPellets<=0 and not gameEnded then gameEnded=true running=false showEndGame("🏆 You Win!\nScore: "..score) end end)