Straight to the point, I made a system where when E is held the SurfaceGUI has a textlabel which gets It’s position tweened down and when it’s at a certain position an event is fired but I am having problem with the tweening part, I want to make a tween function instead of reusing tween all the time but problem is when E is not held no more the tween still continues and doesn’t go back after that.
function Tween(Time, state)
local tweenInfo = TweenInfo.new(
Time,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
)
local tween = TweenService:Create(script.Parent.TextLabel, tweenInfo, {Position = UDim2.new(0, 0, 0.99, 0)})
if state == true then
tween:Play()
else
tween:Cancel()
script.Parent.TextLabel.Position = UDim2.new(0,0,0,0)
end
end
UserInputService.InputBegan:connect(function(Input, GameProcessed)
if ClosestObject ~= nil then
if UserInputService:GetFocusedTextBox() == nil then
while UserInputService:IsKeyDown(Enum.KeyCode.E) do
Held = true
wait()
if Held == true then
local Data = ClosestObject:FindFirstChild("Data")
Timer = Data.Time.Value
script.Parent.Main.BackgroundTransparency = 0.45
Tween(Timer, true)
if script.Parent.TextLabel.Position == UDim2.new(0,0,0.99,0) then
if Data then
local Event = Data:FindFirstChild("Event")
if Event then
local Offset = (HumanoidRootPart.CFrame.Position-ClosestObject.Center.Position)
local ray = Ray.new(ClosestObject.Center.Position, Offset.Unit*Offset.magnitude)
local Wall,Hit = workspace:FindPartOnRayWithIgnoreList(ray,{ClosestObject,HumanoidRootPart.Parent})
if Wall then
print("wall")
else
Event.Value:FireServer(Data)
end
end
end
end
end
end
end
end
end)
UserInputService.InputEnded:connect(function(Input, GameProcessed)
if Input.UserInputType == Enum.UserInputType.Keyboard then
if Input.KeyCode == Enum.KeyCode.E then
Held = false
Tween(Timer, false)
script.Parent.TextLabel.Position = UDim2.new(0,0,0,0)
script.Parent.Main.BackgroundTransparency = 0
end
end
end)