Advertisement
ailenkai

Flappy Bird script

Sep 23rd, 2023
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.90 KB | None | 0 0
  1. repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
  2. game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Anchored = true
  3. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
  4. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  5. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)
  6. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.SelfView, false)
  7. local InputService = game:GetService("UserInputService")
  8. local TouchService = game:GetService("TouchInputService")
  9. local RS = game:GetService("ReplicatedStorage")
  10. local RunService = game:GetService("RunService")
  11. local TweenService = game:GetService("TweenService")
  12. local GUI = script.Parent:FindFirstChild("Game")
  13. local updatescore = RS.updatescore
  14. local Pipes = GUI.Pipes
  15. local Bird = GUI.Bird
  16. local birdhome = Bird.Position
  17. local assets = GUI.assets
  18. local PlayButton = GUI.playbutton
  19. local Score = GUI.score
  20.  
  21. local BG1 = GUI.bg1
  22. local BG1Image = GUI.bg1.Image
  23. local BG2 = GUI.bg2
  24. local BG2Image = GUI.bg2.Image
  25. local tweeninfo = TweenInfo.new(10,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  26. local bg1tween = TweenService:Create(BG1, tweeninfo, {Position = UDim2.new(-1,0,0,0)})
  27. local bg2tween = TweenService:Create(BG2, tweeninfo, {Position = UDim2.new(0,0,0,0)})
  28.  
  29. local scoreval = 0
  30. local scored = false
  31.  
  32. local playing = false
  33. local velocity = 0
  34. local pipespeed = 4 -- lower == faster
  35.  
  36.  
  37. local function physics()
  38.     if velocity < 1 then
  39.         velocity = velocity + 0.002
  40.     end
  41. end
  42.  
  43. function touching(a,b)
  44.     local ap = Vector2.new(a.Position.X.Scale, a.Position.Y.Scale)
  45.     local as = Vector2.new(a.Size.X.Scale, a.Size.Y.Scale)
  46.     local bp = Vector2.new(b.Position.X.Scale, b.Position.Y.Scale)
  47.     local bs = Vector2.new(b.Size.X.Scale, b.Size.Y.Scale)
  48.     local c = (ap.x + as.x > bp.x) and (bp.x + bs.x > ap.x) and (ap.y + as.y > bp.y) and (bp.y + bs.y > ap.y)
  49.     if c then
  50.         return true
  51.     else
  52.         return false
  53.     end
  54. end
  55.  
  56. local function updateBirdPos()
  57.     Bird.Position = UDim2.new(0.166,0,Bird.Position.Y.Scale + velocity,0)--falling
  58.     velocity = velocity * 0.9
  59.     Bird.Rotation = velocity*450
  60. end
  61.  
  62. local pipe = Pipes:GetChildren()
  63.  
  64. local function collision()
  65.     if playing then
  66.         --wall
  67.         for i = 1, #pipe do
  68.             if pipe[i]:IsA("ImageLabel") then
  69.                 if touching(pipe[i],Bird) then
  70.                     playing = false
  71.                     bg1tween:Cancel()
  72.                     bg2tween:Cancel()
  73.                     BG1.Position = UDim2.new(0,0,0,0)
  74.                     BG2.Position = UDim2.new(1,0,0,0)
  75.                 end
  76.             end
  77.         end
  78.         --point
  79.         for i = 1, #pipe do
  80.             if pipe[i]:IsA("Frame") and not scored then
  81.                 if touching(pipe[i],Bird) then
  82.                     print("potato")
  83.                     scored = true
  84.                     spawn(function()
  85.                         delay(1.5,function()
  86.                             scored = false
  87.                         end)
  88.                     end)
  89.                     scoreval = scoreval + 1
  90.                     Score.Text = "".. scoreval .." 社会信用!"
  91.                     if scoreval >= game:GetService("Players").LocalPlayer:WaitForChild("leaderstats")["顶级社会信用"].Value then
  92.                         updatescore:FireServer(scoreval)
  93.                     end
  94.                     --updatescore:FireServer(scoreval)
  95.                 end
  96.             end
  97.         end
  98.     end
  99. end
  100.  
  101.  
  102.  
  103. local function clearMap()
  104.     for _, v in pairs(pipe)do
  105.         if v.Name == "pipe" or v.Name == "point" then
  106.             v.Visible = false
  107.             v:Remove()
  108.         end
  109.     end
  110. end
  111.  
  112. local function createpoint()
  113.     local frame = Instance.new("Frame")
  114.     frame.Name = "point"
  115.     frame.BackgroundTransparency = 1
  116.     frame.Size = UDim2.new(0.076,0,1,0)
  117.     frame.Position = UDim2.new(1,0,0,0)
  118.     frame.Parent = Pipes
  119.     return frame
  120. end
  121.  
  122. local function createSound(id, volume, looped, playonremove)
  123.     local Sound = Instance.new("Sound")
  124.     Sound.Looped = looped
  125.     Sound.SoundId = id
  126.     Sound.Volume = volume
  127.     Sound.PlayOnRemove = playonremove
  128.     return Sound
  129. end
  130.  
  131. local function generatepipes()
  132.     if playing then
  133.         local random = math.random(10,60)/100
  134.         local point = createpoint()
  135.         local top = assets.pipe:Clone()
  136.         top.Parent = Pipes
  137.         top.Position = UDim2.new(1,0,0,0)
  138.         top.Size = UDim2.new(0.076,0,random,0)
  139.         local bottom = assets.pipe:Clone()
  140.         bottom.Parent = Pipes
  141.         bottom.Size = UDim2.new(0.076,0,(0.9-top.Size.Y.Scale)-.4,0)
  142.         local bottommath = 1-bottom.Size.Y.Scale
  143.         bottom.Position = UDim2.new(1,0,bottommath,0)
  144.         local tweeninfo = TweenInfo.new(pipespeed,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
  145.         local toptween = TweenService:Create(top, tweeninfo, {Position = UDim2.new(-0.1,0,0,0)})
  146.         local pointtween = TweenService:Create(point, tweeninfo, {Position = UDim2.new(-0.1,0,0,0)})
  147.         local bottomtween = TweenService:Create(bottom, tweeninfo, {Position = UDim2.new(-0.1,0,bottommath,0)})
  148.         pipe = Pipes:GetChildren()
  149.         toptween:play()
  150.         pointtween:play()
  151.         bottomtween:play()
  152.         delay(pipespeed, function()
  153.             top:Remove()
  154.             top = nil
  155.             bottom:Remove()
  156.             bottom = nil
  157.         end)
  158.     end
  159. end
  160.  
  161. spawn(function()
  162.     while task.wait(2) do
  163.         generatepipes()
  164.     end
  165. end)
  166.  
  167. local function gravity()
  168.     if playing then
  169.         physics()
  170.         updateBirdPos()
  171.         collision()
  172.     else
  173.         Bird.Position = birdhome
  174.         Bird.Rotation = 0
  175.         PlayButton.Visible = true
  176.     end
  177. end
  178.  
  179. InputService.InputBegan:connect(function(input)
  180.     if input.KeyCode == Enum.KeyCode.Space then
  181.         print("gaben")
  182.         velocity = velocity - 0.065
  183.         if not playing then
  184.             PlayButton.Visible = false
  185.             scoreval = 0
  186.             Score.Text = "0 社会信用!"
  187.             playing = true
  188.             bg1tween:play()
  189.             bg2tween:play()
  190.             delay(20,function()
  191.                 bg1tween:play()
  192.                 bg2tween:play()
  193.             end)
  194.         end
  195.     end
  196. end)
  197.  
  198. if InputService.TouchEnabled then
  199.     InputService.TouchTap:connect(function(input)
  200.         print("gaben")
  201.         velocity = velocity - 0.065
  202.         if not playing then
  203.             PlayButton.Visible = false
  204.             scoreval = 0
  205.             Score.Text = "0 社会信用!"
  206.             playing = true
  207.             bg1tween:play()
  208.             bg2tween:play()
  209.             delay(20,function()
  210.                 bg1tween:play()
  211.                 bg2tween:play()
  212.             end)
  213.         end
  214.     end)
  215. end
  216.  
  217. PlayButton.MouseButton1Click:connect(function()
  218.     local obunga = createSound("rbxassetid://3061644602",0.5,false)
  219.     obunga.Parent = GUI
  220.     obunga:Play()
  221. end)
  222.  
  223. local bgpoop = 1
  224. RunService.Heartbeat:connect(function()
  225.     pipe = Pipes:GetChildren()
  226.     gravity()
  227.     if BG1.Position == UDim2.new(-1,0,0,0) and bgpoop == 1 then
  228.         bgpoop = 2
  229.         BG1.Image = BG2Image
  230.         BG2.Image = BG1Image
  231.         BG1.Position = UDim2.new(0,0,0,0)
  232.         BG2.Position = UDim2.new(1,0,0,0)
  233.         bg1tween:play()
  234.         bg2tween:play()
  235.     elseif BG1.Position == UDim2.new(-1,0,0,0) and bgpoop == 2 then
  236.         bgpoop = 1
  237.         BG1.Image = BG1Image
  238.         BG2.Image = BG2Image
  239.         BG1.Position = UDim2.new(0,0,0,0)
  240.         BG2.Position = UDim2.new(1,0,0,0)
  241.         bg1tween:play()
  242.         bg2tween:play()
  243.     end
  244.     if not playing then
  245.         clearMap()
  246.         velocity = 0
  247.     end
  248. end)
  249.  
  250. local randomsounds = {"rbxassetid://2619237842","rbxassetid://5235532522","rbxassetid://1372387751","rbxassetid://3442983711","rbxassetid://6622083025"}
  251.  
  252. spawn(function()
  253.     while task.wait(math.random(20,30)) do
  254.         local rs = createSound(randomsounds[math.random(1,#randomsounds)],1,false)
  255.         rs.Parent = GUI
  256.         rs:Play()
  257.     end
  258. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement