Why is the code not working?

I want to open CodeFrame but it’s not working, please help

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Open.Value == false then
		script.Parent.Parent.Open.Value = true
		script.Parent.Parent.CodeFrame:TweenPosition(UDim2.new(0.5, -200, 0.5, -150), "InOut", "Sine", 1, true)
	else
		script.Parent.Parent.Open.Value = false
		script.Parent.Parent.CodeFrame:TweenPosition(UDim2.new(0.5, -200, 1.5, -150), "InOut", "Sine",1,true)
	end
end)

image

Add print statements, see if the event fires at all.

It might be that the EasingDirection and the EasingStyle are wrong.
They are not strings, they are Enums.

replace the EasingDirection string with Enum.EasingDirection.InOut.
replace the EasingStyle string with Enum.EasingStyle.Sine.

And can you specify what’s not working? The animation not playing or nothing at all?

2 Likes

The CodeFrame is not coming when I click the CodeButton.

Have you tested the things I put in my last comment? And are there any errors?

1 Like

Double check if the frame is visible, and that the Udim2 values are correctly represented.

Unrelated but :TweenPosition is actually deprecated in favour of Tweenservice. Won’t make much of a difference but just an FYI!

You can actually use strings in place of Enums as long as the name matches. Saves a bit of time and looks cleaner in my opinion :stuck_out_tongue: This is wrong! TIL that enum references aren’t actually strings, embarrassing.

2 Likes

its not a string its enum you should do something like this


also whoever teached you please dont listen to him again

2 Likes

plz dont spread misinformation

3 Likes

based on the previous replies, the code should look like this (also if this works don’t mark my reply as the solution, mark skelly’s instead)

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

local button = script.Parent

local CodeUI = button.Parent
local CodeFrame = CodeUI.CodeFrame
local Open = CodeUI.Open

local tween = nil
button.MouseButton1Click:Connect(function()
	if Open.Value == false then
		Open.Value = true
		
		if tween ~= nil then
			tween:Cancel()
			tween = nil
		end
		
		tween = TweenService:Create(CodeFrame, tweenInfo, {Position = UDim2.new(0.5, -200, 0.5, -150)})
		tween:Play()
	else
		Open.Value = false
		
		if tween ~= nil then
			tween:Cancel()
			tween = nil
		end
		
		tween = TweenService:Create(CodeFrame, tweenInfo, {Position = UDim2.new(0.5, -200, 1.5, -150)})
		tween:Play()
	end
end)
1 Like

Thanks for calling me out, I could’ve sworn that was the case but research tells me that I’m totes wrong. TIL, preciate it!

(Sorry OP!)

1 Like

i hope i helped :sob:

--//Service

local TweenService = game:GetService("TweenService")

--//Function

local function Tween(Instance: Instance, TweenInfo: TweenInfo, PropertiesTable: {any})
	return TweenService:Create(Instance, TweenInfo, PropertiesTable)
end

--//Variables

local Button = script.Parent
local Open = Button.Parent.Open
local CodeFrame = Button.Parent.CodeFrame

local TweenVariable = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true)

--//Main

Button.MouseButton1Click:Connect(function()
	if not Open.Value then
		Open.Value = true
		
		Tween(CodeFrame, TweenVariable, {Position = UDim2.new(0.5, -200, 0.5, -150)}):Play()
	else
		Open.Value = false
		Tween(CodeFrame, TweenVariable, {Position = UDim2.new(0.5, -200, 1.5, -150)}):Play()
	end 
end)
2 Likes

It is still not working but thanks for the assistance

but are there any errors in the output? if not, did u make sure that CodeFrame’s Visible property is set to true?

In output it says it is working but in game it’s not showing

i see. your code for the button makes it so that CodeFrame moves, but not making it visible. i suggest turning Visible on and move CodeFrame’s Position to 0.5, -200, 1.5, -150

basically, you say “it’s not working” because CodeFrame is invisible

1 Like

but if u purposely turned it off, make it so that the script also toggles Visible

1 Like

Okay I tried, it is still not showing, I think it is corrupted or something idk

can you provide a screen recording?

1 Like

-Visibile is true
-No errors are showing in the output
-All the names are correct and checked thrice
-Code is correct

1 Like

Try checking how the properties of the frame is changing after you clicked the button.

2 Likes