Attempting to make a sonic gravity controller

So I really want to make a gravity controller for a roblox sonic game, but I think I’m pretty lost. I was inspired by the last reply to this post (besides my replies): How to make a gravity control for a Sonic Game to continue the quest/journey of making a sonic gravity controller. In that post, someone said to use a function to check the players speed. If they have enough speed, they will activate the gravity controller. My knowledge is pretty small (probably the reason why I’m struggling on this), so I tried to do this (image was also in the other post, I just want to give people a gist of things):
Screenshot (1869)

and this:

but both of them didn’t work. What am I doing wrong? Am I editing the wrong script? Am I typing the function incorrectly?

2 Likes

The default humanoid walkspeed is 16 i think. Did you change it so it can be greater than 50?

I have a momentum script for testing. It allows the player to get more speed the more they walk which is how they gain speed. My problem is that the gravity controller still controls fine even when I don’t have the required speed. What in the script do I fix to make it so that it activates when the player has reached a certain speed?

I think you should change your if statement

if speed <= 50 then
		return
	end

this way you are checking if the actual player speed is above the threshold because the humanoid.WalkSpeed is more of a constant speed that the player acelerates to, maybe im wrong i have never played with gravity controllers but that may help

image
first value is the speed argument, while the second one is the walkspeed, this is in a default baseplate but that could be helpful

as I said my scripting knowledge is pretty small. I’m not new here, but I’m not that good, so I’m pretty confused with what you think I should change It’s just a small question, but how does saying

if speed <=50 then
return
end

do anything if “speed” isn’t specified? I just want an explanation that’s all

In your code

if humanoid.WalkSpeed <= 50 then return end

what you are doing is reading the humanoid WalkSpeed, and then if the humanoid.WalkSpeed is equal or lower than 50 you will end your function, humanoid.WalkSpeed is the property that describes how quickly the humanoid can walk, while speed is the current speed that the humanoid is moving at so changing WalkSpeed for speed is making the script check if the current humanoid speed is equal or lower than 50 and if so, end the function

What i gues you want to do is check if the current humanoid speed is greater than 50 which is done with that if statement, and then run whatever gravity thing you are doing

I’m also making a Sonc game

WalkSpeed is a variable that is your current target speed for your Humanoid, not the current speed they are going at, hence being able to have a walk speed of 200 and move at a speed of say, 25 (due to friction or other stuff)

in order to check the actual speed that the player is going at you could use the Humanoid.Running event

so something like

local Player = game.Player.LocalPlayer
local Char = Player.Character
local Hum = Char:WaitForChild("Humanoid")

Hum.Running:Connect(function(speed)
  if speed < 50 then
  -- your code
  end
end)

would only fire your code as long as your character is going less than 50 studs/s

okay but what if I want to check their walkspeed, not their actual speed?

this is my current code, yet it doesn’t really work as intended. It doesn’t look right and it doesn’t change the controller at all. What did I do wrong?

local Player = game.Player.LocalPlayer
local Char = Player.Character
local Hum = Char:WaitForChild("Humanoid")

Hum.Running:Connect(function(speed)
	if speed < 50 then
	    return
	end
	
	if (Controller) then
		Controller:Destroy()
		Controller = nil
	elseif script.Parent.Humanoid.WalkSpeed > 50 then
		Controller = GravityController.new(PLAYERS.LocalPlayer)
		Controller.GetGravityUp = GetGravityUp
	end
end)

for anyone who stumbles upon this post, I’m trying to turn this input requirement script:

game:GetService("ContextActionService"):BindAction("Toggle", function(action, state, input)
	if not (state == Enum.UserInputState.Begin) then
		return
	end
	
	if (Controller) then
		Controller:Destroy()
		Controller = nil
	else
		Controller = GravityController.new(PLAYERS.LocalPlayer)
		Controller.GetGravityUp = GetGravityUp
	end
end, false, Enum.KeyCode.K)

into a speed requirement script. How can I make something like that?

I’m lost. Everything I’m doing to the script either breaks the controller or doesn’t change the controller what so ever. Can someone please help me?

it may not be much, but I made it so whenever you press the toggle button, it’ll wait until you’re at a certain walkspeed in order to actually go into wall stick mode. This is the current script (not the entire gravity script, just the input part):

game:GetService("ContextActionService"):BindAction("Toggle", function(action, state, input)
	if not (state == Enum.UserInputState.Begin) then
		return
	end
	
	if (Controller) then
		Controller:Destroy()
		Controller = nil
	else
		repeat 
		wait (1) 
		until
		script.Parent.Humanoid.WalkSpeed >= 49
		Controller = GravityController.new(PLAYERS.LocalPlayer)
		Controller.GetGravityUp = GetGravityUp
	end
end, false, Enum.KeyCode.K)

any ideas on how to improve on this?