Momentum script breaks player movement. How do I fix this?

I made a sonic gravity controller (using Egomoose’ gravity controller) and wanted to add downwards and upwards momentum, so I made a short script that increases your walk speed depending on the orientation of your character. After I made the script, I play tested my game and my character couldn’t move. I tested this multiple times and became sure that the orientation momentum script is the one breaking the gravity controller. Do you guys have any reasons why?

script:

local HRP = script.Parent.HumanoidRootPart
local orientZ = HRP.Orientation.Z
local orientX = HRP.Orientation.X

script.Parent.Humanoid.Running:Connect(function()
	if orientZ == 0 then
		script.Parent.Humanoid.WalkSpeed = script.Parent.Humanoid.WalkSpeed + 10000000000
	end
end)

The script works whenever I turn off the gravity controller, but this is supposed to slow down/ speed up the player whenever they’re walking on walls with the controller ON. Any reason why this is happening?

1 Like

i have a couple of questions

why are you adding absurd amounts of walkspeed?

is the orienx variable supposed to be outside of the connection?

1 Like

for the first question, I added absurd amounts of walkspeed in order to be 100% sure if the script works. For the second question ,the “orientx” isn’t being used in the script YET. I want to make sure a basic version of the script works before I add on to it

1 Like

i meant to say orienz mb isnt it supposed to be inside the connection if you are checking it?

1 Like

what do you mean? It’s already in the function, unless I did something wrong

1 Like

try this, not sure if this causes the problem but its definitely isnt supposed to be like that, you are checking the rootparts orientation only once

local HRP = script.Parent.HumanoidRootPart

script.Parent.Humanoid.Running:Connect(function()
local orientZ = HRP.Orientation.Z
local orientX = HRP.Orientation.X
	if orientZ == 0 then
		script.Parent.Humanoid.WalkSpeed = script.Parent.Humanoid.WalkSpeed + 10000000000
	end
end)

heres the thing though, both the scripts I made and you made works perfectly, but only when the gravity controller is turned off. When it’s turned on, it just doesn’t work

1 Like

are there any errors or warnings? if not ive never looked into gravity controllers code so i cant say much

Everytime I turn the controller off, this error message gets repeated like CRAZY:

1 Like

So what I did is make a Sign with a TextLabel and the Text of the TextLabel be equal to Orientation Z.
So if Orientation Z is equal to 0, the TextLabel will also be equal to 0.
And I can just make a simple if sentence where if the TextLabel’s text will be equal to 0 the WalkSpeed will be increased.

local HRP = script.Parent.HumanoidRootPart
local Hum = script.Parent.Humanoid
local RunService = game:GetService("RunService")

--the sign
local sign = Instance.new("Part",game.Workspace)
local SurfaceGui = Instance.new("SurfaceGui",sign)
local text = Instance.new("TextLabel")
text.Parent = sign.SurfaceGui

--check
RunService.Heartbeat:Connect(function(deltaTime)
print(text.Text)
end)

--making the orientationZ be euqal to Label
RunService.Heartbeat:Connect(function(deltaTime)
local orientZ = HRP.Orientation.Z
local orientX = HRP.Orientation.X
text.Text = orientZ
end)

RunService.Heartbeat:Connect(function(deltaTime)
--the if sentence 
if text.Text == "0" then Hum.WalkSpeed = Hum.WalkSpeed +1000
elseif Hum.MoveDirection == Vector3.new (0, 0, 0) then Hum.WalkSpeed = Hum.WalkSpeed
end
end)

Hahaha, that’s the first time I’ve ever seen that particular way of checking!

If you wanna make sure your code is running, use a print statement:

if 2 + 2 == 4 then
    print("Math is cool")
else
    print("Computer broke")
end

Then view the Output window to see what prints:

If you don’t see the Output window, right click the top bar up here and enable it:

2 Likes

ok so what I found out the problem was is that you used script.Parent.HumanoidRunning:Connect(function() as a sort of loop
of which the controller denies for some reason.

What you could do to fix that is use another form of loop like RunService.Heartbeat:Connect(function()