(Use this) New Module: https://create.roblox.com/store/asset/90939572208441/
Legacy Module: https://create.roblox.com/store/asset/14144240995/
If you find any bugs, please make a reply about them here.
Finally, after time and time, I have finally finished the complete revamp of this module.
How it works is very simple, if you are familiar with the CameraShaker Module
How to use this???
Oh, simpler than you think.
Let’s create a script where once you click a TextButton, the button will shake a little
local Button = script.Parent:WaitForChild("TextButton")
local InterfaceShaker = require(game:GetService("ReplicatedStorage"):WaitForChild("InterfaceShaker"))
local function OnClick()
InterfaceShaker.ShakeOnce(Button, 10, 0, 0, 0.2)
end
Button.MouseButton1Click:Connect(OnClick)
-- InterfaceShaker.ShakeOnce(element, magnitude, duration, fadeIn, fadeOut)
This is probably everything you need to know.
However, you can also make the module only rotate the element:
local function OnClick()
InterfaceShaker.ApplyPosition = false
InterfaceShaker.ShakeOnce(Button, 10, 0.1, 0, 0.4)
end
Or, the opposite, only make it Position stuff.
local function OnClick()
InterfaceShaker.ApplyRotation = false
InterfaceShaker.ShakeOnce(Button, 10, 0.1, 0, 0.4)
end
You can view the source code here:
local module = {
["Threads"] = {},
["StartPositions"] = {},
["StartRotations"] = {},
["CancelEvents"] = {},
["ApplyPosition"] = true,
["ApplyRotation"] = true,
}
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local RNG = Random.new()
function module.ShakeOnce(element : GuiObject, magnitude, duration, fadeIn, fadeOut)
if not module.ApplyPosition and not module.ApplyRotation then
return
end
local ExistingThread = module.Threads[element]
if ExistingThread then
module.CancelEvents[element]:Fire()
task.cancel(module.Threads[element])
module.Threads[element] = nil
end
local PreviousPosition = module.StartPositions[element] or element.Position
local PreviousRotation = module.StartRotations[element] or element.Rotation
local CancelBindable = Instance.new("BindableEvent")
local OnCancel = CancelBindable.Event
if not module.StartPositions[element] then
module.StartPositions[element] = PreviousPosition
end
module.StartRotations[element] = PreviousRotation
module.CancelEvents[element] = CancelBindable
module.Threads[element] = task.spawn(function()
local _v1 = (magnitude/800)
local _v2 = (magnitude)
local _r2 = {
multiplier = Instance.new("NumberValue"), -- markipliers
rotation = Instance.new("NumberValue"),
position = Instance.new("Vector3Value"),
}
_r2.multiplier.Value = 0
local Connection : RBXScriptConnection
local ConnectionCancel : RBXScriptConnection
local Main = task.spawn(function()
local lastValue = Vector3.zero
Connection = RunService.RenderStepped:Connect(function(delta)
local rangeX = RNG:NextNumber(-_v1, _v1)
local rangeY = RNG:NextNumber(-_v1, _v1)
local rangeR = RNG:NextNumber(-_v2, _v2)
_r2.position.Value = Vector3.new(
rangeX,
rangeY,
0
)
if module.ApplyPosition then
element.Position = PreviousPosition + UDim2.fromScale(
(_r2.position.Value.X) * _r2.multiplier.Value,
(_r2.position.Value.Y) * _r2.multiplier.Value
)
end
_r2.rotation.Value = rangeR
if module.ApplyRotation then
element.Rotation = PreviousRotation + _r2.rotation.Value * _r2.multiplier.Value
end
end)
end)
local v = task.spawn(function()
TweenService:Create(
_r2.multiplier,
TweenInfo.new(fadeIn, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
{Value = 1}
):Play()
task.wait(fadeIn)
_r2.multiplier.Value = 1
task.wait(duration)
TweenService:Create(
_r2.multiplier,
TweenInfo.new(fadeOut, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut),
{Value = 0}
):Play()
task.wait(fadeOut)
_r2.multiplier.Value = 0
CancelBindable:Fire()
end)
ConnectionCancel = OnCancel:Connect(function()
task.cancel(Main)
task.cancel(v)
Connection:Disconnect()
ConnectionCancel:Disconnect()
CancelBindable:Destroy()
_r2.rotation:Destroy()
_r2.position:Destroy()
_r2.multiplier:Destroy()
_r2 = {}
module.Threads[element] = nil
end)
end)
end
return module
Thanks, bye!!!