|
| 19 Oct 2015 12:29 PM |
All the script does is for each frame in the alphabet up to M, it changes the buy button text,colour and makes the buy script inside it disabled based on if you have enough credits or if you already own that ship.
I don't know how to make my script efficient, any ideas? script:
local player = game.Players.LocalPlayer local ls = player:findFirstChild("leaderstats") local Credits = ls:findFirstChild("Credits") local Hangar1 = ls:findFirstChild("Hangar1") local Hangar2 = ls:findFirstChild("Hangar2") local Hangar3 = ls:findFirstChild("Hangar3") local Self = script.Parent
while true do wait(1) -- Ship_Frame_A if Hangar1.Value == Self.Ship_Frame_A.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_A.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_A.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_A.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_A.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_A.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_A.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_A.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_A.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_A.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_A.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_B if Hangar1.Value == Self.Ship_Frame_B.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_B.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_B.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_B.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_B.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_B.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_B.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_B.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_B.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_B.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_B.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_C if Hangar1.Value == Self.Ship_Frame_C.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_C.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_C.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_C.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_C.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_C.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_C.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_C.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_C.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_C.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_C.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_D if Hangar1.Value == Self.Ship_Frame_D.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_D.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_D.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_D.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_D.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_D.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_D.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_D.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_D.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_D.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_D.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_E if Hangar1.Value == Self.Ship_Frame_E.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_E.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_E.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_E.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_E.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_E.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_E.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_E.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_E.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_E.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_E.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_F if Hangar1.Value == Self.Ship_Frame_F.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_F.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_F.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_F.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_F.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_F.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_F.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_F.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_F.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_F.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_F.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_G if Hangar1.Value == Self.Ship_Frame_G.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_G.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_G.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_G.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_G.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_G.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_G.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_G.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_G.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_G.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_G.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_H if Hangar1.Value == Self.Ship_Frame_H.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_H.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_H.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_H.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_H.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_H.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_H.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_H.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_H.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_H.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_H.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_I if Hangar1.Value == Self.Ship_Frame_I.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_I.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_I.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_I.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_I.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_I.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_I.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_I.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_I.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_I.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_I.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_J if Hangar1.Value == Self.Ship_Frame_J.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_J.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_J.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_J.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_J.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_J.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_J.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_J.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_J.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_J.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_J.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_K if Hangar1.Value == Self.Ship_Frame_K.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_K.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_K.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_K.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_K.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_K.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_K.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_K.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_K.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_K.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_K.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_L if Hangar1.Value == Self.Ship_Frame_L.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_L.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_L.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_L.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_L.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_L.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_L.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_L.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_L.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_L.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_L.Buy_Now.TextColor3 = Color3.new (255, 0, 0)
-- Ship_Frame_M if Hangar1.Value == Self.Ship_Frame_M.Select_Hangar.ShipToBuy.Value or Hangar2.Value == Self.Ship_Frame_M.Select_Hangar.ShipToBuy.Value or Hangar3.Value == Self.Ship_Frame_M.Select_Hangar.ShipToBuy.Value then Self.Ship_Frame_M.Buy_Now.Buy_Now.Disabled = true Self.Ship_Frame_M.Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self.Ship_Frame_M.Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self.Ship_Frame_M.Buy_Now.Buy_Now.Disabled = false Self.Ship_Frame_M.Buy_Now.Text = "BUY NOW" Self.Ship_Frame_M.Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self.Ship_Frame_M.Select_Hangar.ShipPrice.Value then Self.Ship_Frame_M.Buy_Now.TextColor3 = Color3.new (255, 0, 0) end end end end end end end end end end end end end end end end end end end end end end end end end end end
|
|
|
| Report Abuse |
|
|
| 19 Oct 2015 12:36 PM |
| also forgot to add, it checks to see if you already own that ship by checking each stat hangar1,hangar2,hangar3 and then seeing if any of them = to the int value inside each frame with the alphabet letter. |
|
|
| Report Abuse |
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 19 Oct 2015 12:59 PM |
note: untested, but i think this is generally what you're looking for
local player = game.Players.LocalPlayer local ls = player:findFirstChild("leaderstats") local Credits = ls:findFirstChild("Credits") local Self = script.Parent
for i=1,13 do local owned = false for j = 1, 3 do // three is the number of hangers, right? if Self["Ship_Frame_"..string.char(64+i)].Select_Hangar.ShipToBuy.Value==ls["Hangar"..j].Value then owned = true break end end if (owned) then Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Buy_Now.Disabled = true Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Buy_Now.Disabled = false Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Text = "BUY NOW" Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self["Ship_Frame_"..string.char(64+i)].Select_Hangar.ShipPrice.Value then Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (255, 0, 0) end end |
|
|
| Report Abuse |
|
|
| 19 Oct 2015 01:16 PM |
@Solotaire, thank you so much.
Also it seems to work with the while true do at the start of it. Will this be safe to use or could it crash?
local player = game.Players.LocalPlayer local ls = player:findFirstChild("leaderstats") local Credits = ls:findFirstChild("Credits") local Self = script.Parent
while true do wait() for i=1,13 do local owned = false for j = 1, 3 do if Self["Ship_Frame_"..string.char(64+i)].Select_Hangar.ShipToBuy.Value==ls["Hangar"..j].Value then owned = true break end end
if (owned) then Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Buy_Now.Disabled = true Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Text = "YOU ALREADY OWN THIS SHIP" Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (255, 255, 255) else Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Buy_Now.Disabled = false Self["Ship_Frame_"..string.char(64+i)].Buy_Now.Text = "BUY NOW" Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (0, 255, 0) if Credits.Value < Self["Ship_Frame_"..string.char(64+i)].Select_Hangar.ShipPrice.Value then Self["Ship_Frame_"..string.char(64+i)].Buy_Now.TextColor3 = Color3.new (255, 0, 0) end end end end
|
|
|
| Report Abuse |
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 19 Oct 2015 01:30 PM |
The while loop would be the least efficient part of the script. The for loop mostly just makes it look nicer afaik. Why do you need to check on it every frame of the game (oh, and if you do need to do this, RenderStepped might be better)?
If this is for a shop like I think it is, you can just update it when the gui is opened. |
|
|
| Report Abuse |
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 19 Oct 2015 01:31 PM |
| you'd also need to update it after you buy something, but either way, it's still significantly less. |
|
|
| Report Abuse |
|