The Title itself might be self explanatory, but if not, I’m trying to enable a Tween when a Frame is Visible while also making sure another Frame isnt Visible. Pretty much, I’m making a 2D Game with only UI, and I’m currently struggling to script the main purpose of the game, “the Obby” or whatever you want to call it. I’m not an expert scripter (as you can see), but I’d really appreciate some help. The following script is meant to make it so the Obstacle moves accross the other side of the Frame:
local PlayFrame = script.Parent.Parent.Parent.Parent.PlayFrame
local CountdownFrame = script.Parent.Parent.Parent.CountdownFrame
local Obstacle = script.Parent
if PlayFrame.Visible == true and CountdownFrame.Visible == false then
Obstacle:TweenPosition(
UDim2.new(-0.001, 0,0.859, 0),
"In",
"Linear",
.5,
false
)
end
if script.Parent.Position == "-0.001, 0,0.859, 0" then
Obstacle:TweenSize(
UDim2.new(0.001, 0,0.082, 0),
"In",
"Linear",
.5,
false
)
end
Please inform me if you need more information about the properties of each thing.
The problem is this script is running only one time, when the player joins, you need to detect when the frames visibility changes, like this:
local PlayFrame = script.Parent.Parent.Parent.Parent.PlayFrame
local CountdownFrame = script.Parent.Parent.Parent.CountdownFrame
local Obstacle = script.Parent
PlayFrame:GetPropertyChangedSignal("Visible"):Connect(function()
if PlayFrame.Visible == true and CountdownFrame.Visible == false then
Obstacle:TweenPosition(
UDim2.new(-0.001, 0,0.859, 0),
"In",
"Linear",
.5,
false
)
end
if script.Parent.Position == "-0.001, 0,0.859, 0" then
Obstacle:TweenSize(
UDim2.new(0.001, 0,0.082, 0),
"In",
"Linear",
.5,
false
)
end
end)
Tried it, but it works only when I press the back button to go to other Frames and go back to the PlayFrame. And it works while the CountdownFrame is visible aswell…but at least it moved, unlike before
idk if its helpful, but here is a visual of the PlayFrame:
local PlayFrame = script.Parent.Parent.Parent.Parent.PlayFrame
local CountdownFrame = script.Parent.Parent.Parent.CountdownFrame
local Obstacle = script.Parent
PlayFrame:GetPropertyChangedSignal("Visible"):Connect(function()
if PlayFrame.Visible == true and CountdownFrame.Visible == false then
Obstacle:TweenPosition(
UDim2.new(-0.001, 0,0.859, 0),
"In",
"Linear",
.5,
false
)
end
if script.Parent.Position == UDim2.new(-0.001, 0,0.859, 0) then
Obstacle:TweenSize(
UDim2.new(0.001, 0,0.082, 0),
"In",
"Linear",
.5,
false
)
end
end)
Sorry for the late reply, I was eating. I also just tried this and the issue is the same as before, it moves after I’ve pressed the Back button and returned to the PlayFrame, once again while CountdownFrame is visible
Once again really sorry for the late reply (i have a really busy schedule) I don’t think the else statement fits anywhere. Based on what I’m trying to do, once the PlayFrame is Visible while the CountdownFrame isn’t, then tween, and the position the tween will put it to is -0.001, 0,0.859, 0. Then, once it’s set to that position (which is the corner of the frame it’s in), then tween, and the side the tween will put it to is 0.001, 0,0.082, 0. No really sure where the else statement could be used
Actually I just gave it some thought after my previous reply, you meant for whether the Frames are visible, right? for example, “if Frame is Visible and Frame isnt Visible, then do tween script, else do nothing”, right? Is that what you meant perhaps?