Created
February 3, 2025 15:22
-
-
Save 4x8Matrix/b40b0c4d079c76ea26738ce9bc3354e8 to your computer and use it in GitHub Desktop.
HapticFeedback.luau
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --[[ | |
| 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