Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game:GetService("Players").LocalPlayer
- local Mouse = Player:GetMouse()
- local Items = {}
- local ValidNames = {
- ["Door"] = true,
- ["Gate"] = true,
- ["Lockdown Door"] = true
- }
- local InteractionDistance = 15
- local CurrentItem = nil
- local UI = Player:WaitForChild("PlayerGui"):WaitForChild("InteractionUI")
- local TS = game:GetService("TweenService")
- local UIS = game:GetService("UserInputService")
- local Event = game:GetService("ReplicatedStorage").InteractionEvent
- local ClientInteract = true
- Event.OnClientEvent:Connect(function(State,Response,Item)
- if UI.Primary.TextTransparency ~= 0 then
- TS:Create(UI.Primary,TweenInfo.new(.3,Enum.EasingStyle.Linear),{TextTransparency = 0}):Play()
- TS:Create(UI.Secondary,TweenInfo.new(.3,Enum.EasingStyle.Linear),{TextTransparency = 0}):Play()
- end
- if State == false then
- ClientInteract = false
- UI.Primary.TextColor3 = Color3.fromRGB(200,50,50)
- UI.Secondary.TextColor3 = Color3.fromRGB(200,50,50)
- UI.Primary.Text = "INTERACTION FAILED;"
- UI.Secondary.Text = Response
- for _,Reader in pairs(Item.OtherParts.Readers:GetChildren()) do
- for _,Outline in pairs(Reader.Frame:GetChildren()) do
- if Outline:IsA("SelectionBox") then
- Outline.Color3 = Color3.fromRGB(200,50,50)
- end
- end
- end
- wait(3)
- ClientInteract = true
- else
- ClientInteract = false
- UI.Primary.TextColor3 = Color3.fromRGB(50,200,50)
- UI.Secondary.TextColor3 = Color3.fromRGB(50,200,50)
- UI.Primary.Text = "INTERACTION COMPLETED;"
- UI.Secondary.Text = Response
- for _,Reader in pairs(Item.OtherParts.Readers:GetChildren()) do
- for _,Outline in pairs(Reader.Frame:GetChildren()) do
- if Outline:IsA("SelectionBox") then
- Outline.Color3 = Color3.fromRGB(50,200,50)
- end
- end
- end
- wait(3)
- ClientInteract = true
- end
- end)
- UIS.InputBegan:Connect(function(Input,GPE)
- if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.E and GPE == false and CurrentItem ~= nil and ClientInteract == true then
- Event:FireServer(CurrentItem)
- ClientInteract = false
- wait(1)
- ClientInteract = true
- end
- end)
- for _,Item in pairs(workspace:GetChildren()) do
- if Item:FindFirstChildWhichIsA("BoolValue") and ValidNames[Item:FindFirstChildWhichIsA("BoolValue").Name] then
- Item:FindFirstChildWhichIsA("BoolValue").Value = true
- table.insert(Items,1,Item)
- elseif Item:IsA("Model") or Item:IsA("Folder") then
- for _,SecondCheckItem in pairs(Item:GetChildren()) do
- if SecondCheckItem:FindFirstChildWhichIsA("BoolValue") and ValidNames[SecondCheckItem:FindFirstChildWhichIsA("BoolValue").Name] then
- SecondCheckItem:FindFirstChildWhichIsA("BoolValue").Value = true
- table.insert(Items,1,SecondCheckItem)
- end
- end
- end
- end
- spawn(function()
- while wait() do
- if ClientInteract == true then
- if CurrentItem ~= nil then
- if UI.Primary.TextTransparency ~= 0 then
- UI.Primary.Text = string.upper(CurrentItem:FindFirstChildWhichIsA("BoolValue").Name).." PROMPT;"
- UI.Secondary.Text = "Press [E] to interact with the "..CurrentItem:FindFirstChildWhichIsA("BoolValue").Name.."."
- UI.Primary.TextColor3 = Color3.fromRGB(200,200,200)
- UI.Secondary.TextColor3 = Color3.fromRGB(200,200,200)
- TS:Create(UI.Primary,TweenInfo.new(.3,Enum.EasingStyle.Linear),{TextTransparency = 0}):Play()
- TS:Create(UI.Secondary,TweenInfo.new(.3,Enum.EasingStyle.Linear),{TextTransparency = 0}):Play()
- end
- for _,Reader in pairs(CurrentItem.OtherParts.Readers:GetChildren()) do
- if not Reader.Frame:FindFirstChildWhichIsA("SelectionBox") then
- local Outline = Instance.new("SelectionBox")
- Outline.Color3 = Color3.fromRGB(255,255,255)
- Outline.LineThickness = .02
- Outline.Transparency = 1
- Outline.Parent = Reader.Frame
- Outline.Adornee = Reader.Frame
- TS:Create(Outline,TweenInfo.new(.15),{Transparency = 0}):Play()
- end
- end
- local Main = CurrentItem.InteractionParts.Interact
- if (Player.Character.HumanoidRootPart.Position - Main.Position).Magnitude > InteractionDistance or Mouse.Target ~= Main then
- for _,Reader in pairs(CurrentItem.OtherParts.Readers:GetChildren()) do
- if Reader.Frame:FindFirstChildWhichIsA("SelectionBox") then
- spawn(function()
- pcall(function()
- local Outline = Reader.Frame:FindFirstChildWhichIsA("SelectionBox")
- TS:Create(Outline,TweenInfo.new(.15),{Transparency = 1}):Play()
- repeat wait() until Outline.Transparency == 1
- Outline:Destroy()
- end)
- end)
- end
- end
- CurrentItem = nil
- end
- else
- if UI.Primary.TextTransparency ~= 1 then
- TS:Create(UI.Primary,TweenInfo.new(.1,Enum.EasingStyle.Linear),{TextTransparency = 1}):Play()
- TS:Create(UI.Secondary,TweenInfo.new(.1,Enum.EasingStyle.Linear),{TextTransparency = 1}):Play()
- end
- for _,Item in pairs(Items) do
- local Main = Item.InteractionParts:WaitForChild("Interact")
- if (Player.Character:WaitForChild('HumanoidRootPart').Position - Main.Position).Magnitude <= InteractionDistance and Mouse.Target == Main then
- CurrentItem = Item
- end
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement