Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Items/Shop Handler
- local StarterGUI = game:GetService("StarterGui")
- StarterGUI:SetCore("TopbarEnabled", false)
- local Items = workspace:WaitForChild("Items")
- local Players = game:GetService("Players")
- local Storage = game:GetService("ReplicatedStorage")
- local RS = game:GetService("RunService")
- local TS = game:GetService("TweenService")
- local UIS = game:GetService("UserInputService")
- local Utils = Storage:WaitForChild("Modules").Utils
- local SpringModule = require(Utils.spr)
- local Player = Players.LocalPlayer
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local ItemsStorage = {};
- local objetInspecting = nil
- local canInteract = true
- local isInspecting = false
- local isRotating = false
- local Mouse = Player:GetMouse()
- local PrimaryPart = Character:WaitForChild('HumanoidRootPart')
- local yesCon;
- local noCon;
- local bv;
- for _,v in pairs(Items:GetChildren()) do
- -- Setting name/cost values
- if v:FindFirstChild('ItemInfo') then
- local itemName = v.ItemInfo.ItemName.Value
- local price = v.ItemInfo.Cost.Value
- v.ItemInfo.TextLabel.Text = itemName..' ($'.. price..')'
- end
- end
- RS.RenderStepped:Connect(function()
- for _,v in pairs(Items:GetChildren()) do
- local distance = (PrimaryPart.Position - v.Position).magnitude
- if distance <= 5.8 then
- ItemsStorage[v.Name] = v
- else
- if ItemsStorage[v.Name] then
- ItemsStorage[v.Name] = nil
- end
- end
- if ItemsStorage[v.Name] then
- SpringModule.target(v.ItemInfo, 0.6, 1.6, {
- Size = UDim2.fromScale(5, 5),
- })
- else
- SpringModule.target(v.ItemInfo, 0.6, 1.6, {
- Size = UDim2.fromScale(5, 0),
- })
- if script.Parent.BuyConfirmation.itemBuying.Value == v.ItemInfo.ItemName.Value then
- if yesCon ~= nil and noCon ~= nil then
- SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
- Size = UDim2.fromScale(0.243, 0),
- Position = UDim2.fromScale(0.378, 0.95)
- })
- coroutine.resume(coroutine.create(function()
- script.Parent.BuyConfirmation.itemBuying.Value = ''
- wait(0.5)
- script.Parent.BuyConfirmation.Visible = false
- end))
- yesCon:Disconnect()
- noCon:Disconnect()
- yesCon = nil
- noCon = nil
- coroutine.resume(coroutine.create(function()
- wait(2)
- canInteract = true
- end))
- end
- end
- end
- end
- end)
- UIS.InputBegan:Connect(function(input, gpe)
- if gpe then return end
- if input.KeyCode == Enum.KeyCode.E then
- if canInteract == false then return end
- canInteract = false
- bv = Instance.new("BodyVelocity", PrimaryPart)
- bv.Name = 'BuyBV'
- bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- bv.Velocity = Vector3.new(0,0,0)
- Character.Humanoid.JumpPower = 0
- Character.Humanoid.AutoRotate = false
- -- inspect
- local fadeFrame = script.Parent.Frame
- fadeFrame.Visible = true
- for i = 1,0,-0.1 do
- fadeFrame.BackgroundTransparency = i
- wait()
- end
- for name,values in pairs(ItemsStorage) do
- print("Inspect ".. name)
- local Camera = workspace.CurrentCamera
- Camera.CameraType = Enum.CameraType.Scriptable
- Camera.CFrame = values.ItemInfo.PartView.CFrame
- objetInspecting = values
- end
- script.Parent.Info.Visible = true
- script.Parent.Info.TextLabel.Text = objetInspecting.ItemInfo.ItemName.Value..' ($'.. objetInspecting.ItemInfo.Cost.Value..')'
- wait(2)
- for i = 0,1,0.1 do
- fadeFrame.BackgroundTransparency = i
- wait()
- end
- isInspecting = true
- fadeFrame.Visible = false
- end
- if input.KeyCode == Enum.KeyCode.F then
- if canInteract == false then return end
- if isRotating == true then return end
- if isInspecting == true then return end
- for name,dist in pairs(ItemsStorage) do
- canInteract = false
- if bv == nil then
- bv = Instance.new("BodyVelocity", PrimaryPart)
- bv.Name = 'BuyBV'
- bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- bv.Velocity = Vector3.new(0,0,0)
- Character.Humanoid.JumpPower = 0
- Character.Humanoid.AutoRotate = false
- end
- print("Buy ".. name)
- script.Parent.BuyConfirmation.itemBuying.Value = dist.ItemInfo.ItemName.Value
- script.Parent.BuyConfirmation.Visible = true
- SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
- Size = UDim2.fromScale(0.243, 0.07),
- Position = UDim2.fromScale(0.378, 0.84)
- })
- yesCon = script.Parent.BuyConfirmation.Yes.Button.MouseButton1Click:Connect(function()
- -- buy weapon here
- -- check if have enough money etc etc.
- -- cool fade in on the left notify effect
- -- after all done then...
- SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
- Size = UDim2.fromScale(0.243, 0),
- Position = UDim2.fromScale(0.378, 0.95)
- })
- warn('Player has requested to buy item '.. name..' | Cost: '.. dist.ItemInfo.Cost.Value)
- bv:Destroy()
- bv = nil
- Character.Humanoid.JumpPower = 50
- Character.Humanoid.AutoRotate = true
- coroutine.resume(coroutine.create(function()
- wait(0.5)
- script.Parent.BuyConfirmation.Visible = false
- wait(2)
- canInteract = true
- end))
- yesCon:Disconnect()
- noCon:Disconnect()
- end)
- noCon = script.Parent.BuyConfirmation.No.Button.MouseButton1Click:Connect(function()
- -- declined
- SpringModule.target(script.Parent.BuyConfirmation, 0.6, 1.6, {
- Size = UDim2.fromScale(0.243, 0),
- Position = UDim2.fromScale(0.378, 0.95)
- })
- bv:Destroy()
- bv = nil
- Character.Humanoid.JumpPower = 50
- Character.Humanoid.AutoRotate = true
- coroutine.resume(coroutine.create(function()
- wait(0.5)
- script.Parent.BuyConfirmation.Visible = false
- wait(2)
- canInteract = true
- end))
- yesCon:Disconnect()
- noCon:Disconnect()
- end)
- end
- end
- if input.UserInputType == Enum.UserInputType.MouseButton2 then
- if isInspecting == false then return end
- isRotating = true
- end
- end)
- UIS.InputEnded:Connect(function(input, gpe)
- if gpe then return end
- if input.UserInputType == Enum.UserInputType.MouseButton2 then
- isRotating = false
- end
- end)
- UIS.InputChanged:Connect(function(input, gpe)
- if gpe then return end
- if input.UserInputType == Enum.UserInputType.MouseMovement then
- if isInspecting == false then return end
- if isRotating == false then return end
- local screenSize = workspace.CurrentCamera.ViewportSize
- local mousePos = (UIS:GetMouseLocation() - screenSize / 2) * (2/screenSize)
- local sensitivity = Vector2.new(-5,-5)
- local rotation = CFrame.Angles(
- math.rad(mousePos.X * sensitivity.X),
- 0,
- 0
- )
- objetInspecting.ItemInfo.InspectView.CFrame = objetInspecting.ItemInfo.InspectView.CFrame * rotation
- end
- end)
- script.Parent.Info.StopInspect.Button.MouseButton1Click:Connect(function()
- if isInspecting == false then return end
- isInspecting = false
- isRotating = false
- script.Parent.Frame.Visible = true
- for i = 1,0,-0.1 do
- script.Parent.Frame.BackgroundTransparency = i
- wait()
- end
- script.Parent.Info.Visible = false
- local obj = objetInspecting.ItemInfo.InspectView
- obj.Orientation = Vector3.new(0,0,0)
- objetInspecting = nil
- workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
- bv:Destroy()
- bv = nil
- Character.Humanoid.JumpPower = 50
- Character.Humanoid.AutoRotate = true
- wait(2)
- for i = 0,1,0.1 do
- script.Parent.Frame.BackgroundTransparency = i
- wait()
- end
- script.Parent.Frame.Visible = false
- wait(2)
- canInteract = true
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement