So what I want is to make my image move up and down non stop, its the icon for the robux shop button in my game and I’d like to make it move up and down,
Unfortunately I haven’t found anything to help me, I already read all the GUiobject page on roblox, searched the dev forum but I don’t seem to find anything to help me.
Here’s the code I have right now, what I did is make a tween to move it up and one to move it down and put the both of them in a loop, but the only thing that happens is it moves up and gets stuck up and doesn’t move back down.
code:
local TweenService = game:GetService("TweenService")
local Image = script.Parent
local normalPosition = UDim2.new(0.525, 0,0.524, 0)
local targetPosition = UDim2.new(0.525, 0,0.45, 0)
local upTween = TweenService:Create(
Image,
TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut),
{Position = targetPosition}
)
local downTween = TweenService:Create(
Image,
TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut),
{Position = normalPosition}
)
while true do
wait (.1)
for i=1, 30 do
upTween:Play()
wait(1)
downTween:Play()
wait(0)
end
end
No for is needed, just check if the Tween is finished and redo it again
local image = script.Parent
local oldPosition = image.Position
local Yp = 5
local Speed = 0.8
local Up = game.TweenService:Create(image, TweenInfo.new(Speed, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut), {
Position = UDim2.new(image.Position.X.Scale, image.Position.X.Offset, image.Position.Y.Scale, image.Position.Y.Offset - Yp)
})
local Down = game.TweenService:Create(image, TweenInfo.new(Speed, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut), {
Position = oldPosition
})
coroutine.wrap(function() --Continue the code below the loop
while wait() do
Up:Play()
Up.Completed:Wait()
Down:Play()
Down.Completed:Wait()
end
end)()
I might need help with something else too, so I also have this script that makes the gui object bigger whenever u hover over it right, but since I want all guibuttons to do that I’d have to manually change the size every time, would you be able to help me with a script so that it automatically gets the size and just adds a certain amount to it? I tried to implement what you did in the moving up and down code the way u got the old postion and all but that didnt work at all, heres what I have right now:
code:
local image = script.Parent
local normalSize = UDim2.new(0.061, 0, 0.111, 0)
local hoverSize = UDim2.new(0.07, 0, 0.12, 0)
image.MouseEnter:Connect(function()
image:TweenSize(hoverSize,
Enum.EasingDirection.Out, -- I set it to Default (Out)
Enum.EasingStyle.Elastic, -- I set it to Elastic
1, -- I set it to 5 for a long tween
true -- I set it just incase there is another tween happening
)
end)
image.MouseLeave:Connect(function()
image:TweenSize(normalSize,
Enum.EasingDirection.Out, -- I set it to Default (Out)
Enum.EasingStyle.Elastic, -- I set it to Elastic
.5, -- I set it to 5 for a long tween
true -- I set it just incase there is another tween happening
)
end)
If you want to increase the size instead of the position, you will have to add a property called “UIScale” to all the buttons you want it to increase, and make the Button always stay at AnchorPoint {0.5, 0.5}, so that the button is increased in “its own position”, if the AnchorPoint is at {0, 0}, the movement will be strange, but it depends on each taste. Here is the modified excerpt:
local Client = game:GetService("Players").LocalPlayer
local PlayerGui = Client.PlayerGui
local ScaleIn = 1.3
local Speed = 0.1
coroutine.wrap(function()
while wait(1) do -- Delay 1 Seconds Updating
for _, w in pairs(PlayerGui:GetDescendants()) do
if (w:IsA("GuiButton") and not w:GetAttribute("Setted")) then
if not (w:FindFirstChildOfClass("UIScale")) then
warn(w, "does not have a UIScale") -- Warn in output
else
w:SetAttribute("Setted", true)
local DefaultScale = w:FindFirstChildOfClass("UIScale").Scale
w.MouseEnter:Connect(function()
game.TweenService:Create(w:FindFirstChildOfClass("UIScale"), TweenInfo.new(Speed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
Scale = ScaleIn
}):Play()
end)
w.MouseLeave:Connect(function()
game.TweenService:Create(w:FindFirstChildOfClass("UIScale"), TweenInfo.new(Speed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
Scale = DefaultScale
}):Play()
end)
end
end
end
end
end)()