Hey Developers!
Basically all I want to do is make an “E to Interact” gui. I want it to whenever you hold for 5ish seconds, it do something. I’m not actually sure how I’ll manage that, but I’ll get there. My current problem is the fact that I cannot for the life of me get this animation to stop. I feel a bit dumb here, but heres my current code, inside a LocalScript in StarterGui. Thanks!
Code:
local UIS = game:GetService("UserInputService")
local HRP = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart')
local key = Enum.KeyCode.E
local db = false
local function isEbeingHeld()
return UIS:IsKeyDown(key)
end
local function began()
local TI = TweenInfo.new(
5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false,
0
)
local TS = game:GetService("TweenService")
local createAnim = TS:Create(workspace.ClassicSword.Handle.BillboardGui.eMain.Frame, TI, {Size = UDim2.new(0, 50, 0, -50)})
if not isEbeingHeld() then
createAnim:Stop()
else
createAnim:Play()
end
end
UIS.InputBegan:Connect(function(input, isTyping)
if input.KeyCode == key and not isTyping then
began()
end
end)
-- Side Code
while wait() do
if (workspace.ClassicSword.Handle.Position - HRP.Position).magnitude < 20 then
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = math.huge
workspace.ClassicSword.Handle.BillboardGui.Enabled = true
else
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = 0
workspace.ClassicSword.Handle.BillboardGui.Enabled = false
end
end
(I’ve got the E to Interact working, but I cannot get the frame to stop tweening upward. I’ve tried using :Stop() and :Pause(), but they do not seem to work the way in which I’m trying to get them to…)
local Tween = TweenService:Create(Object, TweenInformation, {Goal})
local function OnInputBegan(Input)
if Input.KeyCode == KeyCode then
Tween:Play()
end
end
local function OnInputEnded(Input)
if Input.KeyCode == KeyCode then
Tween:Cancel()
end
end
UserInputService.InputBegan:Connect(OnInputBegan)
UserInputService.InputEnded:Connect(OnInputEnded)
To fit your code
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
local createAnim = TS:Create(workspace.ClassicSword.Handle.BillboardGui.eMain.Frame, TI, {Size = UDim2.new(0, 50, 0, -50)})
local function OnInputBegan(Input)
if Input.KeyCode == KeyCode then
createAnim:Play()
end
end
local function OnInputEnded(Input)
if Input.KeyCode == KeyCode then
createAnim:Cancel()
end
end
UIS.InputBegan:Connect(OnInputBegan)
UIS.InputEnded:Connect(OnInputEnded)
Sorry for the late-ish reply, I’m looking more to have it where they Hold E for 5 or so seconds, and if they release in the middle of those 5 seconds, the tween stops.
Hmm, you could set the time for the gui to move is 5 seconds, then in this function, change cancel to pause, the tween will resume when you press e again.
local function OnInputEnded(Input)
if Input.KeyCode == KeyCode then
createAnim:Pause()
end
end
Oof, so the problem isn’t… horrible?.. Though it’ll definitely break my game haha. Basically with the code I’ve posted just below, it stops the animation, yes, but I want it to set the size to 0,0,0,0 aswell. The game-breaking part would be the fact that if I continuously spam “E” it does go up, but it’s indeed very glitchy and cuts out.
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
local createAnim = TS:Create(workspace.ClassicSword.Handle.BillboardGui.eMain.Frame, TI, {Size = UDim2.new(0, 50, 0, -50)})
local HRP = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart')
local function OnInputBegan(Input)
if Input.KeyCode == Enum.KeyCode.E then
createAnim:Play()
end
end
local function OnInputEnded(Input)
if Input.KeyCode == Enum.KeyCode.E then
createAnim:Cancel()
end
end
UIS.InputBegan:Connect(OnInputBegan)
UIS.InputEnded:Connect(OnInputEnded)
-- Side Code
while wait() do
if (workspace.ClassicSword.Handle.Position - HRP.Position).magnitude < 20 then
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = math.huge
workspace.ClassicSword.Handle.BillboardGui.Enabled = true
else
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = 0
workspace.ClassicSword.Handle.BillboardGui.Enabled = false
end
end
I’ve tried it, and it does indeed work, as well as I’ve made some changes to what I liked/didnt like. This it definitely a bit off topic, but any way how I’d detect when the tween is done, so I can then award the player a cloned version of the tool? (The sword in workspace is well, a tool xD)
My Current Code:
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
local createAnim = TS:Create(workspace.ClassicSword.Handle.BillboardGui.eMain.Frame, TI, {Size = UDim2.new(0, 50, 0, -50)})
local HRP = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart')
local function OnInputBegan(Input)
if Input.KeyCode == Enum.KeyCode.E then
createAnim:Play()
end
end
local function OnInputEnded(Input)
if Input.KeyCode == Enum.KeyCode.E then
createAnim:Pause()
createAnim:Cancel()
workspace.ClassicSword.Handle.BillboardGui.eMain.Frame.Size = UDim2.new(0, 50, 0, 0)
end
end
UIS.InputBegan:Connect(OnInputBegan)
UIS.InputEnded:Connect(OnInputEnded)
-- Side Code
while wait() do
if (workspace.ClassicSword.Handle.Position - HRP.Position).magnitude < 20 then
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = math.huge
workspace.ClassicSword.Handle.BillboardGui.Enabled = true
else
workspace.ClassicSword.Handle.BillboardGui.MaxDistance = 0
workspace.ClassicSword.Handle.BillboardGui.Enabled = false
end
end
Yeah, I forgot that the tween needed to reset, disreagrd what I’ve said, it’ll work regardless. There’s a check to see if the tween was completed or cancelled, so there should be no issues.
The cancel now completely solves both. You’ve helped me so much on the devforum, I’m so beyond happy to be on this forum with this incredible community. Thank you so much! :))