What do you want to achieve?
I’m making a basic bhop script, I want my game to be compatible with everyone, to be optimal and apart from that, be able to use the FPS Unlocker - I have a 144hz monitor, and believe me, it looks beautiful… but …
What is the problem?
The problem is that when using runservice (I don’t like using while true do) the loop is repeated a lot of times. Normally it should be repeated approximately 60 times. but it repeats itself 144 times APORX
And I want it to remain stable even if you use an FPS Unlocker.
Using FPS Unlocker:
Normal: (Sorry, its repeated)
This is the script:
local nameofscript = script.Name
local nameoffolderscripts = script.Parent.Name
local value = script.Parent.Parent.Parent.Values[nameofscript]
local l__LocalPlayer__1 = game:GetService("Players").LocalPlayer;
local v2 = l__LocalPlayer__1.Character or l__LocalPlayer__1.CharacterAdded:Wait();
local l__HumanoidRootPart__3 = v2:WaitForChild("Torso");
local v4 = Instance.new("BodyVelocity");
v4.Parent = l__HumanoidRootPart__3;
v4.Name = "bhop"
local u1 = nil;
local l__Humanoid__2 = v2:WaitForChild("Humanoid");
local u3 = false;
local function u4()
u1 = l__Humanoid__2:GetState();
if u1 ~= Enum.HumanoidStateType.Freefall then
v4.MaxForce = Vector3.new(0, 0, 0);
v4.Velocity = l__HumanoidRootPart__3.Velocity;
u3 = false;
return;
end;
v4.MaxForce = Vector3.new(5000, 50, 5000);
if not u3 then
v4.Velocity = v4.Velocity * value.Velocity.Value;
u3 = true;
end;
v4.Velocity = v4.Velocity + l__Humanoid__2.MoveDirection * value.MoveDirection.Value;
end;
game:GetService("RunService").Heartbeat:connect(function()
u4();
local speed = l__HumanoidRootPart__3.Velocity.Magnitude;
--script.Parent.Frame.Speed.Text = "Speed: ".. tostring(speed)
--script.Parent.Frame.Velocity.Text = "Velocity: ".. tostring(v4.Velocity)
--script.Parent.Frame.Direction.Text = "Direction: ".. tostring(l__Humanoid__2.MoveDirection)
l__Humanoid__2.JumpPower = value.JumpPower.Value;
end);
l__Humanoid__2.UseJumpPower = true;
game:GetService("UserInputService").JumpRequest:Connect(function()
l__Humanoid__2.JumpPower = value.JumpPower.Value;
end);
l__Humanoid__2.Died:Connect(function()
v4:Destroy();
end);
this is where the delta argument in Heartbeat comes in handy
here, you can do this instead
local function u4(delta)
local magic = delta*60 -- lol. i think this is also called throttling, i'm not too sure myself.
-- in any case, now this magic is used like a multiplier. If you're at 60 fps, magic will be 1. If you're at 30 fps, magic is 2, at 240 fps, magic is 0.25, etc etc.
-- no, magic isn't the proper term for it. I'm just calling it that for s**ts and giggles
u1 = l__Humanoid__2:GetState();
if u1 ~= Enum.HumanoidStateType.Freefall then
v4.MaxForce = Vector3.zero; -- yes Vector3.zero is a thing.
v4.Velocity = l__HumanoidRootPart__3.Velocity;
u3 = false;
return;
end;
v4.MaxForce = Vector3.new(5000, 50, 5000);
if not u3 then
v4.Velocity *= value.Velocity.Value * magic;
u3 = true;
end;
v4.Velocity += l__Humanoid__2.MoveDirection * value.MoveDirection.Value * magic;
end;
game:GetService("RunService").Heartbeat:Connect(function(delta) -- :Connect instead of :connect, :connect is deprecated.
u4(delta);
local speed = l__HumanoidRootPart__3.Velocity.Magnitude;
l__Humanoid__2.JumpPower = value.JumpPower.Value;
end);
local nameofscript = script.Name
local nameoffolderscripts = script.Parent.Name
local value = script.Parent.Parent.Parent.Values[nameofscript]
local LocalPlayer = game:GetService("Players").LocalPlayer;
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait();
local HumanoidRootPart = Character:WaitForChild("Torso");
local BodyVelocity = Instance.new("BodyVelocity"); --v4
BodyVelocity.Parent = HumanoidRootPart;
BodyVelocity.Name = "bhop"
--local u1 = nil;
local Humanoid = Character:WaitForChild("Humanoid");
local VALUE = false;
Humanoid.UseJumpPower = true;
game:GetService("UserInputService").JumpRequest:Connect(function()
Humanoid.JumpPower = value.JumpPower.Value;
end);
Humanoid.Died:Connect(function()
BodyVelocity:Destroy();
end);
local function changevelocity(delta)
local magic = delta*60 -- lol. i think this is also called throttling, i'm not too sure myself.
-- in any case, now this magic is used like a multiplier. If you're at 60 fps, magic will be 1. If you're at 30 fps, magic is 2, at 240 fps, magic is 0.25, etc etc.
-- no, magic isn't the proper term for it. I'm just calling it that for s**ts and giggles
local state = Humanoid:GetState(); --u1
if state ~= Enum.HumanoidStateType.Freefall then
BodyVelocity.MaxForce = Vector3.zero; -- yes Vector3.zero is a thing.
BodyVelocity.Velocity = HumanoidRootPart.Velocity;
VALUE = false;
return;
end;
BodyVelocity.MaxForce = Vector3.new(5000, 50, 5000);
if not VALUE then
BodyVelocity.Velocity *= value.Velocity.Value * 1.2 --* magic;
VALUE = true;
end;
HumanoidRootPart.Velocity += Humanoid.MoveDirection * value.MoveDirection.Value *1.2 --* magic;
end;
game:GetService("RunService").Heartbeat:Connect(function(delta) -- :Connect instead of :connect, :connect is deprecated.
changevelocity(delta);
local speed = HumanoidRootPart.Velocity.Magnitude;
Humanoid.JumpPower = value.JumpPower.Value;
end);