Im making a script that charges a power value up while the mouse is clicked, I noticed that when I was using an FPS Unlocker the value went up faster than when I wasn’t using an FPS Unlocker. (Tested inside Roblox Studio)
Time without FPS Unlocker:
4 seconds
Time with FPS Unlocker:
3.6 seconds
It’s not that drastic of a change but I’m not sure if Im doing something wrong, or its because im inside studio or whatever. I’m still curious to know why this happens. Heres my code:
local UserInputService = game:GetService("UserInputService")
local isMouseClicked: boolean
local MAX_POWER: number = 100
local power: number
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = true
power = 30
while isMouseClicked do
power = math.min(power + 1, MAX_POWER)
print("Power: " .. power)
task.wait(.05)
end
end
end)
UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = false
end
end)
local UserInputService = game:GetService("UserInputService")
local isMouseClicked: boolean
local MAX_POWER: number = 100
local power: number
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = true
power = 30
while isMouseClicked do
local dt = task.wait(.05)
power = math.min(power + (dt / 0.05), MAX_POWER)
print("Power: " .. power)
end
end
end)
UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = false
end
end)
This might be close, just for reference, deltaTime is the time between the last renderstepeed fire (or frame) and the current one.
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local isMouseClicked: boolean
local MAX_POWER: number = 100
local power: number
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = true
power = 30
end
end)
UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isMouseClicked = false
-- power = 0?
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
if isMouseClicked then
power = math.min(power + (deltaTime / 0.05), MAX_POWER)
print("Power: "..power)
end
end)
Im not entirely sure what this is doing but I hope I am atleast somewhat close to getting this right.