Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a leaderboard for this?

Asked by 10 years ago

002

003 local function get(parent,name) while (not parent:FindFirstChild(name)) do wait() end return parent[name] end; 004

005 local plr = game.Players.LocalPlayer 006 local screen = get(script.Parent,"ScreenGui") 007 local workspace = get(screen,"Workspace") 008 local menu = get(workspace,"Menu") 009 local mouse = plr:GetMouse() 010

011 local bird = get(workspace,"Bird") 012

013 local paused,jump = false,false 014 local hit = false 015 local stats = { 016 score = script.Score; 017 best = script.Best; 018 } 019 local settings = { 020 } 021

022 function bird_physics() 023 local grav = 20--14 024 local function collision() 025 for _,v in pairs(workspace.Obstacles:GetChildren()) do 026 local p1x,p1y,p2x,p2y = bird.AbsolutePosition.X,bird.AbsolutePosition.Y,v.AbsolutePosition.X,v.AbsolutePosition.Y 027 local s1x,s1y,s2x,s2y = bird.AbsoluteSize.X,bird.AbsoluteSize.Y,v.AbsoluteSize.X,v.AbsoluteSize.Y 028 if (((((p1y+s1y) >= p2y) and (p1y <= (p2y+s2y))) and (((p1x >= p2x) or ((p1x+s1x) >= p2x)) and (p1x <= (p2x+s2x)))) or ((bird.Position.Y.Offset > 460) or (bird.Position.Y.Offset < 0)) ) then 029 bird:TweenPosition(bird.Position,"Out","Sine",0,true)
030 game_over() 031 end 032 end 033 end 034 while wait() do 035 if ((not paused) and (not jump) and (bird.Visible)) then 036 bird:TweenPosition((bird.Position+UDim2.new(0,0,0,grav)),"Out","Sine",0.1,true) 037 collision() 038 end 039 wait() 040 end 041 end 042

043 function bird_jump() 044 if (paused) then return end 045 jump = true 046 bird.Rotation = -50 047 bird:TweenPosition((bird.Position+UDim2.new(0,0,0,-90)),"Out","Sine",0.15,true) 048 wait(0.25) 049 bird.Rotation = -10 050 jump = false 051 end 052

053 function generate_obstacles() 054 local obj = workspace.Obstacles.Obj:Clone(); workspace.Obstacles.Obj:Remove() 055 local logs = {} 056 local function same_ob(index) 057 local yes = false 058 for _,v in pairs(logs) do 059 if (v == index) then 060 yes = true 061 end 062 end 063 return yes 064 end 065 delay(1,function() while wait() do 066 if (not paused) then 067 for _,v in pairs(workspace.Obstacles:GetChildren()) do 068 v.Position = (v.Position+UDim2.new(0,-6,0,0)) --4 069 if ((v.Position.Y.Scale == 0) and (bird.AbsolutePosition.X > (v.AbsolutePosition.X+v.AbsoluteSize.X)) and (not same_ob(v.Name))) then 070 stats.score.Value = (stats.score.Value+1) 071 table.insert(logs,v.Name) 072 end 073 if (v.AbsolutePosition.X < 435) then v:Remove() end 074 end 075 end 076 wait() 077 end end) 078 delay(3,function() while wait() do -- 140 space 079 if (not paused) then 080 local size1 = math.random(50,360) 081 local size2 = ((500-size1)-140) 082 local new1,new2 = obj:Clone(),obj:Clone() 083 new1.Size,new1.Position = UDim2.new(0,25,0,size1),UDim2.new(1,10,0,0) 084 new2.Size,new2.Position = UDim2.new(0,25,0,size2),UDim2.new(1,10,1,-size2) 085 new1.Name,new2.Name = math.random(),math.random() 086 new1.Parent,new2.Parent = workspace.Obstacles,workspace.Obstacles 087 wait(2) 088 end 089 end end) 090 end 091

092 function game_over() 093 hit,paused = true,true 094 workspace.GameOver.Score.Text = stats.score.Value 095 workspace.GameOver.Visible = true 096 workspace.GameOver.Ok.MouseButton1Up:wait() 097 bird.Position = UDim2.new(0.5,-20,0,200) 098 workspace.GameOver.Visible,menu.Visible = false,true 099 workspace.Obstacles:ClearAllChildren() 100 stats.score.Value = 0 101 end 102

103 function actions() 104 local function update_stats() 105 stats.best.Value = (stats.score.Value > stats.best.Value and stats.score.Value or stats.best.Value) 106 workspace.Score.Current.Text = stats.score.Value 107 workspace.Score.Best.Text = stats.best.Value 108 end 109 mouse.Button1Down:connect(function() 110 bird_jump() 111 end) 112 menu.Play.MouseButton1Up:connect(function() 113 menu.Visible = false 114 paused = false 115 end) 116 menu.Changed:connect(function() 117 bird.Visible,workspace.Obstacles.Visible = (not menu.Visible),(not menu.Visible) 118 paused = menu.Visible 119 end) 120 stats.score.Changed:connect(update_stats) 121 script.Ready.Value = true 122 delay(2,update_stats) 123 end 124

125 while (not plr.Character) do wait() end; plr.Character:Remove() 126

127 actions() 128 generate_obstacles() 129 bird_physics() 130

131 Leaderstats.Score.Value = 0 132

133

134 if (not paused) then 135 for _,v in pairs(workspace.Obstacles:GetChildren()) do 136 v.Position = (v.Position+UDim2.new(0,-6,0,0)) --4 137 if ((v.Position.Y.Scale == 0) and (bird.AbsolutePosition.X > (v.AbsolutePosition.X+v.AbsoluteSize.X)) and (not same_ob(v.Name))) then 138 Leaderstats.Score.value = Leaderstats.Score.Value + 1 139 table.insert(logs,v.Name) 140 end 141 if (v.AbsolutePosition.X < 435) then v:Remove() end 142

143 end 144

Answer this question