Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- @ bakers
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local ServerStorage = game:GetService("ServerStorage")
- local Players = game:GetService("Players")
- local Network = ReplicatedStorage.Network
- local Assets = ReplicatedStorage.Assets
- local Module, Modules = {}, {}
- --
- local Player = Players.LocalPlayer
- local Connections = {}
- -- all interactable objects
- -- used for raycast whitelist
- local Interactables = workspace.Interactables:GetDescendants()
- -- distance from interactable item
- local Distance = 3
- local UI
- local Playing, currentInteraction
- local function CreateRegion3From(Position, Size)
- local SizeOffset = Size/2
- local Point1 = Position - SizeOffset
- local Point2 = Position + SizeOffset
- return Region3.new(Point1, Point2)
- end
- local function cancelCurrentInteraction()
- UI:Destroy()
- currentInteraction = nil
- Playing = false
- end
- local function cancelConnections()
- for _,Connection in pairs(Connections) do
- Connection:Disconnect()
- end
- end
- local function Keyboard(Input, Down, Target)
- if (not Target) then return end
- if (Input == Enum.KeyCode.E) then
- if (Down) then
- if (Target.InUse.Value) then
- Modules.GFX:Glow(UI.Body, {
- Size = UDim2.new(0, UI.AbsoluteSize.X, 0, UI.AbsoluteSize.Y);
- Position = UDim2.new(0, UI.AbsolutePosition.X, 0, UI.AbsolutePosition.Y);
- BackgroundColor3 = Color3.fromRGB(195, 0, 0)
- })
- return
- end
- Modules[Target.Name]:Use(Target)
- -- fill bar
- UI.Body.Fill:TweenSize(UDim2.new(1, 0, 1, 0), "Out", "Linear", Target.Interactable.Value, true, function(Status)
- if (Status == Enum.TweenStatus.Completed) then
- Modules[Target.Name]:Used(Target, true)
- cancelCurrentInteraction()
- end
- end)
- else
- -- empty bar
- UI.Body.Fill:TweenSize(UDim2.new(0, 0, 1, 0), "Out", "Linear", .5, true, function(Status)
- if (Status == Enum.TweenStatus.Completed) then
- Modules[Target.Name]:Used(Target, false)
- cancelCurrentInteraction()
- end
- end)
- end
- end
- end
- function Module:Run()
- local Character = Player.Character
- local Region = CreateRegion3From(Character.HumanoidRootPart.Position, Vector3.new(Distance, Distance, Distance))
- local Parts = workspace:FindPartsInRegion3WithWhiteList(Region, Interactables)
- local Part = Parts[1]
- if (Part) then
- if (not (Part:FindFirstChild("Interactable"))) then return end
- if (Playing) then return end
- if (Part == currentInteraction) then
- return
- else
- cancelConnections()
- currentInteraction = Part
- Playing = true
- end
- if (UI) then
- UI:Destroy()
- end
- UI = Assets.Interface.Billboard.Interact:Clone()
- UI.Parent = currentInteraction
- -- detect whether the user is holding 'e'
- Connections.Input = Network.Bindables.Events.Player.Keyboard.Event:connect(function(Input, Down)
- Keyboard(Input, Down, currentInteraction)
- end)
- else
- cancelConnections()
- if (currentInteraction) then
- cancelCurrentInteraction()
- end
- end
- end
- function Module.Initialise(...)
- Modules = ...
- end
- return Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement