hello, I’m trying to tween a GUI but it doesn’t seem like it would tween at all.
I am still a beginner at scripting so I might need someone to explain what went wrong with this part of the script.
what I am doing here is that I want to make this “circle” GUI to tween to the right when the “play button” is clicked, but whenever I test it, it simply doesn’t work (nothing happens)
local creditB = script.Parent.mainmenu.Credits
local settingsB = script.Parent.mainmenu.settingsbutton
local playB = script.Parent.mainmenu.playbutton
local CR = script.Parent.mainmenu.circle
local CH = script.Parent.mainmenu.characters
playB.MouseButton1Up:Connect(function(click)
CR:TweenPosition(UDim2.new(0,-0.3,0,0))
end)
after a few testing ive finally found an error within output
something like "mainmenu is not a valid member of Frame "Players.Eeveeyaoyao123.PlayerGui.ScreenGui.mainmenu "
I think it gives that error because the startergui loads ‘slowly’. So maybe try waiting for the char to be added or define the circle and characters when the function is triggered.
local MainMenu = script.Parent:WaitForChild("mainmenu")
local creditB = MainMenu.Credits
local settingsB = MainMenu.settingsbutton
local playB = MainMenu.playbutton
local CR = MainMenu.circle
local CH =MainMenu.characters
playB.MouseButton1Up:Connect(function()
CR:TweenPosition(UDim2.new(0,-0.3,0,0), "InOut", "Linear", 0.4, true)
end)
Found the problem! You were mentioning in the script that the mainmenu frame is inside the parent of the script, when in reality, the script is already inside the mainmenu frame.
Use this updated code for your script:
local MainMenu = script.Parent
local creditB = MainMenu:WaitForChild("Credits")
local settingsB = MainMenu:WaitForChild("settingsbutton")
local playB = MainMenu:WaitForChild("playbutton")
local CR = MainMenu:WaitForChild("circle")
local CH = MainMenu:WaitForChild("characters")
playB.MouseButton1Up:Connect(function()
CR:TweenPosition(UDim2.new(0,-0.3,0,0), "InOut", "Linear", 0.4, true)
end)