Hello people of the forums,
I’m trying to make a gui pop up when I press the P key on the keyboard, and close when I press P again. The issue is that when I do push it, the gui pops up, and closes itself imediately after I looked at other people that had the same problem, but I’m also tweening the gui as well, so I don’t know what to do.
Script (in the Frame
local tweenService = game.TweenService
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Exponential,
Enum.EasingDirection.InOut,
0,
false,
0
)
local goal = {
Size = UDim2.new(0.6,0,0.6,0),
BackgroundColor3 = Color3.new(1, 1, 1)
}
local goal2 = {
Size = UDim2.new(0,0,0,0),
BackgroundColor3 = Color3.new(0, 0, 0)
}
local tween = tweenService:Create(script.Parent, tweenInfo, goal)
local tween2 = tweenService:Create(script.Parent, tweenInfo, goal2)
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(imp, gpe)
if gpe then return end
if imp.KeyCode == Enum.KeyCode.P then
if script.Parent.Visible == false then
script.Parent.Visible = true
tween:Play()
tween.Completed:Wait()
end
if script.Parent.Visible == true then
tween2:Play()
tween.Completed:Wait()
script.Parent.Visible = false
end
end
end)
Any help is appreciated, and thank you in addvance.
It is doing what you told it to do..
An else or elseif is what you want here.
First if asks if it’s false, if so make it true. The next if asks if it’s true, if so make it false.
So if it enters false, it will leave false also. You don’t want to split that up like that.
if imp.KeyCode == Enum.KeyCode.P then
if script.Parent.Visible == false then
script.Parent.Visible = true
tween:Play()
tween.Completed:Wait()
else
tween2:Play()
tween.Completed:Wait()
script.Parent.Visible = false
end
end
or
if imp.KeyCode == Enum.KeyCode.P then
if script.Parent.Visible == false then
script.Parent.Visible = true
tween:Play()
tween.Completed:Wait()
elseif script.Parent.Visible == true then
tween2:Play()
tween.Completed:Wait()
script.Parent.Visible = false
end
end
Change “if script.Parent.Visible == true then” to else if script.Parent.Visible == true then
Currently, your versoin changes the frame to visible and then immediatly after that checks again to see if its visible which is true and then closes.
hey, idk if ur still having problems but this works for me. (also added a cooldown for when the animation finished but if u werent going for that feel free too delete)
local tweenService = game.TweenService
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Exponential,
Enum.EasingDirection.InOut,
0,
false,
0
)
local goal = {
Size = UDim2.new(0.6,0,0.6,0),
BackgroundColor3 = Color3.new(1, 1, 1)
}
local goal2 = {
Size = UDim2.new(0,0,0,0),
BackgroundColor3 = Color3.new(0, 0, 0)
}
local tween = tweenService:Create(script.Parent, tweenInfo, goal)
local tween2 = tweenService:Create(script.Parent, tweenInfo, goal2)
local uis = game:GetService("UserInputService")
local cooldown = false
uis.InputBegan:Connect(function(imp, gpe)
if gpe or cooldown then return end
if imp.KeyCode == Enum.KeyCode.P then
cooldown = true
if script.Parent.Visible == false then
script.Parent.Visible = true
tween:Play()
tween.Completed:Wait()
cooldown = false
else
tween2:Play()
tween2.Completed:Wait()
script.Parent.Visible = false
cooldown = false
end
end
end)