FPS Unlocker causes values to add faster?

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)
1 Like

The main reason I’m confused is because I’m not using any RenderStepped/RunService for this code.

1 Like

This is probably something with the while loop, but I’m not sure what it would be. If you needed to fix this you could use deltaTime with runservice.

1 Like

Is this by chance a local script? If so the higher frame rate of a user’s device would cause this to happen.

Could you provide an example of the RunService implementation?

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)

there you go.

1 Like

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.

task.wait() is tied to heartbeat. which runs at FPS.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.