Advertisement
OnFireRobloxScriptin

Shop Button Handler local script

Apr 20th, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --//Variables
  2. local remoteEvent = game.ReplicatedStorage:WaitForChild("OpenShop")
  3. local shop = script.Parent.ShopFrame
  4. local exit = shop.Exit
  5.  
  6. --//Open
  7. remoteEvent.OnClientEvent:Connect(function()
  8.     shop.Visible = true
  9. end)
  10.  
  11. --//Close
  12. exit.MouseButton1Click:Connect(function()
  13.     shop.Visible = false
  14. end)
  15.  
  16. --//Everything above this comment is different for each person depending on what you chose in part 1 of the series
  17.  
  18. local function OpenFrame(frame) --Function for opening frames
  19.     local framefolder = script.Parent.ShopFrame.Information --Variable for Frame Folder
  20.     for _, Frame in ipairs(framefolder:GetChildren()) do --Loop through all the frames in Frame Folder
  21.         if Frame:IsA("Frame") then --If item is a Frame then
  22.             if Frame == frame then --If the item is the Frame we want then
  23.                 Frame.Visible = true --Set the frame's visibility to True
  24.             end
  25.         end
  26.     end
  27. end
  28.  
  29. local function CloseFrames() --Function for closing frames
  30.     local framefolder = script.Parent.ShopFrame.Information --Variable for Frame Folder
  31.     for _, Frame in ipairs(framefolder:GetChildren()) do --Loop through all the frames in Frame Folder
  32.         if Frame:IsA("Frame") then --If the item is a Frame then
  33.             Frame.Visible = false --Set the frame's visibility to False
  34.         end
  35.     end
  36. end
  37.  
  38. --//Buttons
  39. local ClassicSwordButton = shop.Buttons.ClassicSword.ImageButton --Variable for Classic Sword Button
  40. local FlashLightButton = shop.Buttons.FlashLight.ImageButton --Variable for Flash Light Button
  41. --//Frames
  42. local ClassicSwordFrame = shop.Information.ClassicSwordInfo --Variable for Classic Sword Frame
  43. local FlashLightFrame = shop.Information.FlashLightInfo --Variable for Flash Light Frame
  44.  
  45. --//Open Frame Functions
  46. ClassicSwordButton.MouseButton1Click:Connect(function() --When Classic Sword Button is clicked
  47.     CloseFrames() --Close All Frames
  48.     OpenFrame(ClassicSwordFrame) --Open Classic Sword Frame
  49. end)
  50.  
  51. FlashLightButton.MouseButton1Click:Connect(function() --Same thing as Classic Sword but with Flash Light instead
  52.     CloseFrames()
  53.     OpenFrame(FlashLightFrame)
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement