Heya I am really trying to wrap my head around this after all I am simply not a script but I am trying to get a basic grasp of this.
I have tried to find all possible tutorials relaying back to this. I don’t know if I have to change the sizeconstraint or something because I still have that set to relativeXY.
The closest I have gotten is just a rotation script that allows it to rotate permenantly until closed
It is a imagebutton btw.
4 Likes
Do you want the button to shake for as long as the mouse is hovering, or only once when it enters?
1 Like
yup been trying to wrap my head around it ![]()
You can use MouseEnter and MouseLeave to detect when the player hovers on/off the button. Then, use a while loop to make the button shake. After that, all that’s left is a little bit of math using AbsolutePosition and math.random.
local button = script.Parent -- your button here
local originalPosition = button.Position -- used to revert button to it's original position, after the player hovers off the button
local absolutePosition = button.AbsolutePosition -- used to determine button position while shaking
local shakeIntensity = 5 -- how far, in pixels, the button will shake
local hovering
button.MouseEnter:Connect(function()
hovering = true
while hovering do
wait()
local desiredPosition = absolutePosition + Vector2.new(math.random(-shakeIntensity, shakeIntensity), math.random(-shakeIntensity, shakeIntensity))
local newPosition = (desiredPosition - button.Parent.AbsolutePosition) -- subtract the parent's position from the desired position to get its offset
button.Position = UDim2.fromOffset(newPosition.X, newPosition.Y)
end
button.Position = originalPosition -- revert button to it's original position
end)
button.MouseLeave:Connect(function()
hovering = false
end)
11 Likes
Thank you so much, I appreciate those little notes as well will try my hardest to follow that stay safe ![]()
2 Likes