Advertisement
OnFireRobloxScriptin

Shop Button Handler Full Script

May 18th, 2024
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 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. local BuyRE = game.ReplicatedStorage:WaitForChild("Buy")
  6. --//Open
  7. remoteEvent.OnClientEvent:Connect(function()
  8.     shop:TweenPosition( --creates a new tween position
  9.         UDim2.new(0.124,0,0.138,0), --End target for the position tween
  10.         Enum.EasingDirection.InOut, --Direction of tween (not literal direction, its similar to style)
  11.         Enum.EasingStyle.Sine, --Style of tween
  12.         1, --How long the tween takes, 1 = 1 second
  13.         false --If the tween can be overidden by other tweens
  14.     )
  15. end)
  16.  
  17. --//Close
  18. exit.MouseButton1Click:Connect(function()
  19.     shop:TweenPosition( --same thing as the tweenposition above this
  20.         UDim2.new(0.124,0,1,0),
  21.         Enum.EasingDirection.InOut,
  22.         Enum.EasingStyle.Sine,
  23.         1,
  24.         false
  25.     )
  26. end)
  27.  
  28. local function OpenFrame(frame) --Function for opening frames
  29.     local framefolder = script.Parent.ShopFrame.Information --Variable for Frame Folder
  30.     for _, Frame in ipairs(framefolder:GetChildren()) do --Loop through all the frames in Frame Folder
  31.         if Frame:IsA("Frame") then --If item is a Frame then
  32.             if Frame == frame then --If the item is the Frame we want then
  33.                 Frame.Visible = true --Set the frame's visibility to True
  34.             end
  35.         end
  36.     end
  37. end
  38.  
  39. local function CloseFrames() --Function for closing frames
  40.     local framefolder = script.Parent.ShopFrame.Information --Variable for Frame Folder
  41.     for _, Frame in ipairs(framefolder:GetChildren()) do --Loop through all the frames in Frame Folder
  42.         if Frame:IsA("Frame") then --If the item is a Frame then
  43.             Frame.Visible = false --Set the frame's visibility to False
  44.         end
  45.     end
  46. end
  47.  
  48. --//Buttons
  49. local ClassicSwordButton = shop.Buttons.ClassicSword.ImageButton --Variable for Classic Sword Button
  50. local FlashLightButton = shop.Buttons.FlashLight.ImageButton --Variable for Flash Light Button
  51. local KeycardButton = shop.Buttons.Keycard.ImageButton
  52. --//Frames
  53. local ClassicSwordFrame = shop.Information.ClassicSwordInfo --Variable for Classic Sword Frame
  54. local FlashLightFrame = shop.Information.FlashLightInfo --Variable for Flash Light Frame
  55. local KeycardFrame = shop.Information.KeycardInfo
  56.  
  57. --//Open Frame Functions
  58. ClassicSwordButton.MouseButton1Click:Connect(function() --When Classic Sword Button is clicked
  59.     CloseFrames() --Close All Frames
  60.     OpenFrame(ClassicSwordFrame) --Open Classic Sword Frame
  61. end)
  62.  
  63. FlashLightButton.MouseButton1Click:Connect(function() --Same thing as Classic Sword but with Flash Light instead
  64.     CloseFrames()
  65.     OpenFrame(FlashLightFrame)
  66. end)
  67.  
  68. KeycardButton.MouseButton1Click:Connect(function() --Same thing as Classic Sword but with Keycard instead
  69.     CloseFrames()
  70.     OpenFrame(KeycardFrame)
  71. end)
  72.  
  73. BuyRE.OnClientEvent:Connect(function(tool, instruction) --When the client recieves the remote event
  74.     if instruction == "Cash" then --if its the cash error message then
  75.         shop.Errormessage.Text = "Oops! Looks like you don't have enough cash to buy "..tool.."!!!" --cash error message display
  76.         task.wait(3) --wait 3 seconds, replace 3 with the number of seconds you want to wait
  77.         shop.Errormessage.Text = "" --make error message text blank
  78.     elseif instruction == "Max" then --if its the max error message then
  79.         shop.Errormessage.Text = "Oops! Looks like you already bought "..tool.."!!!"
  80.         task.wait(3)
  81.         shop.Errormessage.Text = ""
  82.     end
  83. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement