Advertisement
Aquarius_Raverus

Items Shop src

Oct 4th, 2020
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.76 KB | None | 0 0
  1. -- Items/Shop Handler
  2.  
  3. local StarterGUI = game:GetService("StarterGui")
  4. StarterGUI:SetCore("TopbarEnabled", false)
  5.  
  6. local Items = workspace:WaitForChild("Items")
  7.  
  8. local Players = game:GetService("Players")
  9. local Storage = game:GetService("ReplicatedStorage")
  10. local RS = game:GetService("RunService")
  11. local TS = game:GetService("TweenService")
  12. local UIS = game:GetService("UserInputService")
  13.  
  14. local Utils = Storage:WaitForChild("Modules").Utils
  15. local SpringModule = require(Utils.spr)
  16.  
  17. local Player = Players.LocalPlayer
  18. local Character = Player.Character or Player.CharacterAdded:Wait()
  19.  
  20. local ItemsStorage = {};
  21. local objetInspecting = nil
  22.  
  23. local canInteract = true
  24. local isInspecting = false
  25. local isRotating = false
  26.  
  27. local Mouse = Player:GetMouse()
  28.  
  29. local PrimaryPart = Character:WaitForChild('HumanoidRootPart')
  30.  
  31. local yesCon;
  32. local noCon;
  33. local bv;
  34.  
  35. for _,v in pairs(Items:GetChildren()) do
  36.     -- Setting name/cost values
  37.    
  38.     if v:FindFirstChild('ItemInfo') then
  39.        
  40.         local itemName = v.ItemInfo.ItemName.Value     
  41.         local price = v.ItemInfo.Cost.Value
  42.        
  43.         v.ItemInfo.TextLabel.Text = itemName..' ($'.. price..')'
  44.     end
  45. end
  46.  
  47. RS.RenderStepped:Connect(function()
  48.     for _,v in pairs(Items:GetChildren()) do
  49.        
  50.         local distance = (PrimaryPart.Position - v.Position).magnitude
  51.        
  52.         if distance <= 5.8 then
  53.             ItemsStorage[v.Name] = v
  54.         else
  55.             if ItemsStorage[v.Name] then
  56.                 ItemsStorage[v.Name] = nil
  57.             end
  58.         end
  59.        
  60.         if ItemsStorage[v.Name] then   
  61.            
  62.             SpringModule.target(v.ItemInfo, 0.6, 1.6, {
  63.                 Size = UDim2.fromScale(5, 5),
  64.             })
  65.            
  66.         else
  67.             SpringModule.target(v.ItemInfo, 0.6, 1.6, {
  68.                 Size = UDim2.fromScale(5, 0),
  69.             })
  70.            
  71.             if script.Parent.BuyConfirmation.itemBuying.Value == v.ItemInfo.ItemName.Value then
  72.                 if yesCon ~= nil and noCon ~= nil then
  73.                
  74.                     SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
  75.                         Size = UDim2.fromScale(0.243, 0),
  76.                         Position = UDim2.fromScale(0.378, 0.95)
  77.                     })
  78.                    
  79.                     coroutine.resume(coroutine.create(function()
  80.                         script.Parent.BuyConfirmation.itemBuying.Value = ''
  81.                        
  82.                         wait(0.5)
  83.                         script.Parent.BuyConfirmation.Visible = false
  84.                     end))
  85.                    
  86.                     yesCon:Disconnect()
  87.                     noCon:Disconnect()
  88.                    
  89.                     yesCon = nil
  90.                     noCon = nil
  91.                    
  92.                     coroutine.resume(coroutine.create(function()
  93.                         wait(2)
  94.                         canInteract = true
  95.                     end))
  96.                    
  97.                 end
  98.                
  99.             end
  100.        
  101.         end
  102.        
  103.     end
  104. end)
  105.  
  106. UIS.InputBegan:Connect(function(input, gpe)
  107.     if gpe then return end
  108.    
  109.     if input.KeyCode == Enum.KeyCode.E then
  110.         if canInteract == false then return end
  111.        
  112.         canInteract = false
  113.        
  114.         bv = Instance.new("BodyVelocity", PrimaryPart)
  115.         bv.Name = 'BuyBV'
  116.         bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  117.         bv.Velocity = Vector3.new(0,0,0)
  118.        
  119.         Character.Humanoid.JumpPower = 0
  120.         Character.Humanoid.AutoRotate = false
  121.        
  122.         -- inspect
  123.        
  124.         local fadeFrame = script.Parent.Frame
  125.         fadeFrame.Visible = true
  126.        
  127.         for i = 1,0,-0.1 do
  128.             fadeFrame.BackgroundTransparency = i
  129.             wait()
  130.         end
  131.        
  132.         for name,values in pairs(ItemsStorage) do
  133.             print("Inspect ".. name)
  134.            
  135.             local Camera = workspace.CurrentCamera
  136.            
  137.             Camera.CameraType = Enum.CameraType.Scriptable
  138.             Camera.CFrame = values.ItemInfo.PartView.CFrame
  139.            
  140.             objetInspecting = values
  141.         end
  142.        
  143.         script.Parent.Info.Visible = true
  144.        
  145.         script.Parent.Info.TextLabel.Text = objetInspecting.ItemInfo.ItemName.Value..' ($'.. objetInspecting.ItemInfo.Cost.Value..')'
  146.        
  147.         wait(2)
  148.         for i = 0,1,0.1 do
  149.             fadeFrame.BackgroundTransparency = i
  150.             wait()
  151.         end
  152.        
  153.         isInspecting = true
  154.        
  155.         fadeFrame.Visible = false
  156.        
  157.     end
  158.    
  159.     if input.KeyCode == Enum.KeyCode.F then
  160.         if canInteract == false then return end
  161.         if isRotating == true then return end
  162.         if isInspecting == true then return end
  163.        
  164.         for name,dist in pairs(ItemsStorage) do
  165.             canInteract = false
  166.            
  167.             if bv == nil then
  168.                 bv = Instance.new("BodyVelocity", PrimaryPart)
  169.                 bv.Name = 'BuyBV'
  170.                 bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  171.                 bv.Velocity = Vector3.new(0,0,0)
  172.                
  173.                 Character.Humanoid.JumpPower = 0
  174.                 Character.Humanoid.AutoRotate = false
  175.             end
  176.            
  177.             print("Buy ".. name)
  178.             script.Parent.BuyConfirmation.itemBuying.Value = dist.ItemInfo.ItemName.Value
  179.            
  180.             script.Parent.BuyConfirmation.Visible = true
  181.            
  182.             SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
  183.                 Size = UDim2.fromScale(0.243, 0.07),
  184.                 Position = UDim2.fromScale(0.378, 0.84)
  185.             })
  186.            
  187.             yesCon = script.Parent.BuyConfirmation.Yes.Button.MouseButton1Click:Connect(function()
  188.                 -- buy weapon here
  189.                
  190.                 -- check if have enough money etc etc.
  191.                
  192.                 -- cool fade in on the left notify effect
  193.                
  194.                 -- after all done then...
  195.                
  196.                 SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
  197.                     Size = UDim2.fromScale(0.243, 0),
  198.                     Position = UDim2.fromScale(0.378, 0.95)
  199.                 })
  200.                
  201.                 warn('Player has requested to buy item '.. name..' | Cost: '.. dist.ItemInfo.Cost.Value)
  202.                
  203.                 bv:Destroy()
  204.                 bv = nil
  205.                 Character.Humanoid.JumpPower = 50
  206.                 Character.Humanoid.AutoRotate = true
  207.                
  208.                 coroutine.resume(coroutine.create(function()
  209.                    
  210.                     wait(0.5)
  211.                     script.Parent.BuyConfirmation.Visible = false
  212.                    
  213.                     wait(2)
  214.                    
  215.                     canInteract = true
  216.                 end))
  217.                
  218.                 yesCon:Disconnect()
  219.                 noCon:Disconnect()
  220.             end)
  221.            
  222.             noCon = script.Parent.BuyConfirmation.No.Button.MouseButton1Click:Connect(function()
  223.                 -- declined
  224.                
  225.                 SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
  226.                     Size = UDim2.fromScale(0.243, 0),
  227.                     Position = UDim2.fromScale(0.378, 0.95)
  228.                 })
  229.                
  230.                 bv:Destroy()
  231.                 bv = nil
  232.                 Character.Humanoid.JumpPower = 50
  233.                 Character.Humanoid.AutoRotate = true
  234.                
  235.                 coroutine.resume(coroutine.create(function()
  236.                    
  237.                     wait(0.5)
  238.                     script.Parent.BuyConfirmation.Visible = false
  239.                    
  240.                     wait(2)
  241.                     canInteract = true
  242.                 end))
  243.                
  244.                 yesCon:Disconnect()
  245.                 noCon:Disconnect()
  246.  
  247.             end)
  248.            
  249.         end
  250.     end
  251.    
  252.     if input.UserInputType == Enum.UserInputType.MouseButton2 then
  253.         if isInspecting == false then return end
  254.        
  255.         isRotating = true
  256.     end
  257. end)
  258.  
  259. UIS.InputEnded:Connect(function(input, gpe)
  260.     if gpe then return end
  261.    
  262.     if input.UserInputType == Enum.UserInputType.MouseButton2 then
  263.        
  264.         isRotating = false
  265.     end
  266.    
  267. end)
  268.  
  269. UIS.InputChanged:Connect(function(input, gpe)
  270.     if gpe then return end
  271.    
  272.     if input.UserInputType == Enum.UserInputType.MouseMovement then
  273.         if isInspecting == false then return end
  274.         if isRotating == false then return end
  275.        
  276.    
  277.         local screenSize = workspace.CurrentCamera.ViewportSize
  278.         local mousePos = (UIS:GetMouseLocation() - screenSize / 2) * (2/screenSize)
  279.        
  280.         local sensitivity = Vector2.new(-5,-5)
  281.        
  282.         local rotation = CFrame.Angles(
  283.             math.rad(mousePos.X * sensitivity.X),
  284.             0,
  285.             0
  286.         )
  287.        
  288.         objetInspecting.ItemInfo.InspectView.CFrame = objetInspecting.ItemInfo.InspectView.CFrame * rotation
  289.     end
  290. end)
  291.  
  292. script.Parent.Info.StopInspect.Button.MouseButton1Click:Connect(function()
  293.     if isInspecting == false then return end
  294.    
  295.     isInspecting = false
  296.     isRotating = false
  297.    
  298.     script.Parent.Frame.Visible = true
  299.    
  300.     for i = 1,0,-0.1 do
  301.         script.Parent.Frame.BackgroundTransparency = i
  302.         wait()
  303.     end
  304.    
  305.     script.Parent.Info.Visible = false
  306.    
  307.     local obj = objetInspecting.ItemInfo.InspectView
  308.     obj.Orientation = Vector3.new(0,0,0)
  309.    
  310.     objetInspecting = nil
  311.    
  312.     workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
  313.    
  314.     bv:Destroy()
  315.     bv = nil
  316.     Character.Humanoid.JumpPower = 50
  317.     Character.Humanoid.AutoRotate = true
  318.    
  319.     wait(2)
  320.     for i = 0,1,0.1 do
  321.         script.Parent.Frame.BackgroundTransparency = i
  322.         wait()
  323.     end
  324.     script.Parent.Frame.Visible = false
  325.    
  326.     wait(2)
  327.     canInteract = true
  328. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement