Menu script not working

I’ve been working on adding some menu animations to my Backrooms game and made this script to animate a menu opening.

-- UI
local Credits = script.Parent
local CreditsMenu = script.Parent.Parent.CreditsMenu

-- Tweening variables
endPos = UDim2.new(0.35, 0, 0.15, 0)
startPos = UDim2.new(0.35, 0, 1, 0)
pos = CreditsMenu.Position
tweenService = game.TweenService
speed = TweenInfo.new(0.2)
local open = tweenService:Create(CreditsMenu, speed, endPos)

-- Open menu
Credits.MouseButton1Click:Connect(function()
	print("Button clicked")
	CreditsMenu.Position = startPos
	print("Changed Position")
	CreditsMenu.Visible = true
	print("Menu visible")
	open:Play()
	print("Tweened")
end)

Before I added the tweens, the script worked perfectly fine but now it no longer detects the button being clicked, as none of the prints I added to the function show up. I have everything enabled in the output so I know if they show up I’d see them.

-- UI
local Credits = script.Parent
local CreditsMenu = script.Parent.Parent.CreditsMenu

-- Tweening variables
endPos = {Position = UDim2.new(0.35, 0, 0.15, 0)} -- You must use table for last argument and set property
startPos = UDim2.new(0.35, 0, 1, 0)
pos = CreditsMenu.Position
tweenService = game.TweenService
speed = TweenInfo.new(0.2)
local open = tweenService:Create(CreditsMenu, speed, endPos)

-- Open menu
Credits.MouseButton1Click:Connect(function()
	print("Button clicked")
	CreditsMenu.Position = startPos
	print("Changed Position")
	CreditsMenu.Visible = true
	print("Menu visible")
	open:Play()
	print("Tweened")
end)
1 Like

It seems like the issue might be related to the timing of your Tween. When you set CreditsMenu.Position = startPos, it’s likely that the Tween is trying to animate from the current position (which is already startPos) to endPos, resulting in no visible change and potentially causing the click detection issue.

To fix this, you can set the initial position of CreditsMenu to be outside of the screen or wherever you want it to start before the animation.

Script:

local Credits = script.Parent
local CreditsMenu = script.Parent.Parent.CreditsMenu

endPos = UDim2.new(0.35, 0, 0.15, 0)
startPos = UDim2.new(0.35, 0, 1, 0)
tweenService = game.TweenService
speed = TweenInfo.new(0.2)
local open = tweenService:Create(CreditsMenu, speed, {Position = endPos})

CreditsMenu.Position = UDim2.new(0.35, 0, 1.5, 0)

Credits.MouseButton1Click:Connect(function()
    print("Button clicked")
    CreditsMenu.Visible = true
    print("Menu visible")
    open:Play()
    print("Tweened")
end)

This script sets the initial position of CreditsMenu outside of the screen (UDim2.new(0.35, 0, 1.5, 0) ), and then, when the button is clicked, it sets the Visible property to true and plays the Tween animation. The target position is set directly in the Create method of the Tween, which should resolve the issue you’re facing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.