Hi everyone! so ive been trying to make a menu with a background/pattern looping forever but its not working how i wanted it to
This is when i play in studio
And this is when i play in the game
how do i fix this?
also, heres the script i used:
local MovingImage = script.Parent
while true do
MovingImage:TweenPosition(UDim2.new(0, -5, -0.137, 0),"Out","Linear",2,true)
wait(1)
MovingImage:TweenPosition(UDim2.new(-0.075, 0, -0.25, 0),"Out","Linear",0,true)
wait(0)
end
I believe it’s due to the second tween playing before the first tween is completed
In order to do them asynchronously, you should use TweenService | Roblox Creator Documentation, (this is preferred)
Example :
while true do
local firstTween = TweenService:Create(movingImage, TweenInfo.new(timeDuration, style, direction, ...), { -- table of all the properties to tween
Position = Udim2.new(0, -5, -0.137, 0),
})
firstTween:Play()
firstTween.Completed:Wait()
-- same thing with the second tween
end
You must use Enum | Roblox Creator Documentation in TweenInfo, e.g Enum.EasingStyle.Linear instead of "Linear" and Enum.EasingDirection.Out instead of "Out"
local TweenService = game:GetService("TweenService")
local MovingImage = script.Parent
function CreateTween(Object, Info, Properties)
local Tween = TweenService:Create(Object, Info, Properties)
Tween:Play()
Tween.Completed:Wait()
end
while true do
CreateTween(MovingImage, TweenInfo.new(1, Enum.EasingStyle.Linear), {
Position = UDim2.fromScale(0, -0.135)
})
MovingImage.Position = Udim2.fromScale(-0.075, -0.25)
end
you got an error because you need to use the global Enum
anyways I made a function that works like TweenService:Create, except is also plays the tween and waits for it to finish
also I didn’t use EasingDirection because Enum.EasingDirection.Out is in there by default
local MovingImage = script.Parent
while true do
MovingImage:TweenPosition(UDim2.new(0, -5, -0.137, 0),"Out","Linear",2,true)
task.wait(2)
MovingImage:TweenPosition(UDim2.new(-0.075, 0, -0.25, 0),"Out","Linear",0.5,true)
task.wait(0.5)
end
You set the length of time the tween plays for to two seconds but only wait 1 second before playing the next tween, you also didn’t specify a length of time that the second tween should play for and wait that length of time too so I’ve used 0.5 as an example.
The fact that it works in studio, and does also work in game but not as expected, leads me to think that the problem could possibly be the image aspect ratio scaling. You can see that the studio window size is a different, skinnier size than the game window.
i fixed that and it works, but it goes in both directions at the same speed, what i want is for it to go in one direction and then instantly teleport back to its original position so it looks like it loops forever.
That seems to be caused by using the same TweenInfo with a Time parameter of 1 twice instead of 0 the second time. At that point you could just set the Position as well instead of tweening. Can you please reply with the latest script?
local TweenService = game:GetService("TweenService")
local MovingImage = script.Parent
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
function CreateTween(Object, Info, Properties)
local Tween = TweenService:Create(Object, Info, Properties)
Tween:Play()
Tween.Completed:Wait()
end
while true do
CreateTween(MovingImage, TweenInfo, {
Position = UDim2.new(0, 0, -0.135, 0)
})
CreateTween(MovingImage, TweenInfo, {
Position = UDim2.new(-0.075, 0, -0.25, 0)
})
end
local TweenService = game:GetService("TweenService")
local MovingImage = script.Parent
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
function CreateTween(Object, Info, Properties)
local Tween = TweenService:Create(Object, Info, Properties)
Tween:Play()
Tween.Completed:Wait()
end
while true do
CreateTween(MovingImage, TweenInfo, {
Position = UDim2.new(0, 0, -0.135, 0)
})
MovingImage.Position = UDim2.new(-0.075, 0, -0.25, 0)
end
Possibly because you originally used -0.137 and somewhere it changed to -0.135. Changed it back to -0.137.
local TweenService = game:GetService("TweenService")
local MovingImage = script.Parent
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
function CreateTween(Object, Info, Properties)
local Tween = TweenService:Create(Object, Info, Properties)
Tween:Play()
Tween.Completed:Wait()
end
while true do
CreateTween(MovingImage, TweenInfo, {
Position = UDim2.new(0, 0, -0.137, 0)
})
MovingImage.Position = UDim2.new(-0.075, 0, -0.25, 0)
end