Hello guys.today i finally made my own custom proximity prompt gui for first time ever!
i just wanted to ask if i can change my code for somethings to improve it better.Could i? or the script could be used?
Here it is:
--Services
UserInputService = game:GetService("UserInputService")
TweenService = game:GetService("TweenService")
--Object Variables
UI = script.Parent.Parent
Frame = UI.Frame
PromptName = Frame.PromptName
Keybind = Frame.Keybind
ProcessBarFrame = Frame.ProcessBarFrame
ProcessBar = ProcessBarFrame.ProcessBar
Event = game.ReplicatedStorage.RemoteEvents.Prompt
--Prompt Variables
Title = nil
Time = nil
Key = nil
Data = nil
--Position Variables
ProcessBarFrameStartPosition = UDim2.new(0.08,0,0.822,0)
ProcessBarFrameEndPosition = UDim2.new(0.08,0,1,0)
ProcessBarStartSize = UDim2.new(1,0,1,0)
ProcessBarEndSize = UDim2.new(0,0,1,0)
--Boolean variables
Tweening = false
Enabled = false
--Playing Tweens
PlayingTweens = {}
local function CancelTweens()
for _,tween in pairs(PlayingTweens) do
tween:Cancel()
end
end
local function UpdatePromptAsync(Status,Variable1,Variable2,Variable3,Variable4,Recevied)
if Status == "Show" then
Title = Variable1
Time = Variable2
Key = Variable4
PromptName.Text = Title
Keybind.Text = Variable3
Data = Recevied
UI.Enabled = true
Enabled = true
else
CancelTweens()
PromptName.Position = UDim2.new(0.167,0,0,0)
ProcessBarFrame.Position = ProcessBarFrameEndPosition
ProcessBar.Size = ProcessBarEndSize
Title = nil
Time = nil
Key = nil
PromptName.Text = "N/A"
Keybind.Text = "N/A"
Data = nil
UI.Enabled = false
Enabled = false
end
end
local function Trigger()
if Tweening == true then
Tweening = false
local Tween1 = TweenService:Create(PromptName,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = UDim2.new(0.167,0,0,0)}):Play()
local ProcessBarFrameTween = TweenService:Create(ProcessBarFrame,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = ProcessBarFrameEndPosition}):Play()
local ProcessBarTween = TweenService:Create(ProcessBar,TweenInfo.new(0.1,Enum.EasingStyle.Exponential,Enum.EasingDirection.InOut),{Size = ProcessBarEndSize}):Play()
end
end
local function OnInputBegan(input)
if not Enabled then
return
end
local TitleTween = TweenService:Create(PromptName,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = UDim2.new(0.167,0,-0.25,0)})
local ProcessBarFrameTween = TweenService:Create(ProcessBarFrame,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = ProcessBarFrameStartPosition})
local ProcessBarTween = TweenService:Create(ProcessBar,TweenInfo.new(Time,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Size = ProcessBarStartSize})
if input.KeyCode == Key then
TitleTween:Play()
ProcessBarFrameTween:Play()
ProcessBarTween:Play()
table.remove(PlayingTweens,1)
table.remove(PlayingTweens,2)
table.remove(PlayingTweens,3)
table.insert(PlayingTweens,TitleTween)
table.insert(PlayingTweens,ProcessBarFrameTween)
table.insert(PlayingTweens,ProcessBarTween)
Tweening = true
ProcessBarTween.Completed:Connect(Trigger)
end
end
local function OnInputEnded(input)
if not Enabled then
return
end
local TitleTween2 = TweenService:Create(PromptName,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = UDim2.new(0.167,0,0,0)})
local ProcessBarFrameTween2 = TweenService:Create(ProcessBarFrame,TweenInfo.new(0.2,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position = ProcessBarFrameEndPosition})
local ProcessBarTween2 = TweenService:Create(ProcessBar,TweenInfo.new(0.05,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Size = ProcessBarEndSize})
if input.KeyCode == Key then
Tweening = false
TitleTween2:Play()
ProcessBarFrameTween2:Play()
ProcessBarTween2:Play()
table.remove(PlayingTweens,1)
table.remove(PlayingTweens,2)
table.remove(PlayingTweens,3)
table.insert(PlayingTweens,TitleTween2)
table.insert(PlayingTweens,ProcessBarFrameTween2)
table.insert(PlayingTweens,ProcessBarTween2)
end
end
UserInputService.InputBegan:Connect(OnInputBegan)
UserInputService.InputEnded:Connect(OnInputEnded)
Event.Event:Connect(UpdatePromptAsync)
Here is the explorer:
Thank you guys for who helped me!