Skip to content

Instantly share code, notes, and snippets.

@4x8Matrix
Created February 3, 2025 15:22
Show Gist options
  • Select an option

  • Save 4x8Matrix/b40b0c4d079c76ea26738ce9bc3354e8 to your computer and use it in GitHub Desktop.

Select an option

Save 4x8Matrix/b40b0c4d079c76ea26738ce9bc3354e8 to your computer and use it in GitHub Desktop.
HapticFeedback.luau
--[[
Responsible for vibrating the current mobile device for a given amount of time.
]]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local enableVibration = require(ReplicatedStorage.Shared.Utilities.enableVibration)
local disableVibration = require(ReplicatedStorage.Shared.Utilities.disableVibration)
local vibrationMotorQueue = {
[Enum.VibrationMotor.Large] = {},
[Enum.VibrationMotor.Small] = {},
}
return function(motor: Enum.VibrationMotor, strength: number, duration: number)
local guid = HttpService:GenerateGUID()
table.insert(vibrationMotorQueue[motor], guid)
task.spawn(function()
local awaited = 0
while table.find(vibrationMotorQueue[motor], guid) ~= 1 do
awaited += task.wait()
end
if awaited > duration then
table.remove(vibrationMotorQueue[motor], 1)
return
end
enableVibration(motor, strength)
task.wait(duration - awaited)
disableVibration(motor)
table.remove(vibrationMotorQueue[motor], 1)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment