Disable jumps for a player in a marble

Hi ROBLOXians, I’m beginning to pick up on a marble game that I’ve started on about two years ago, and I’m having trouble disabling the jumps. When I do it the old school way and set the JumpPower to 0 or the Jump boolean to false, it just simply does not work. I’ve looked around, and I don’t see anything that can fix my issue.

Here is my code.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local HRP = char:WaitForChild("HumanoidRootPart")
		local marble = Instance.new("Part",char)
		marble.Name = "marble"
		marble.Size = Vector3.new(7,7,7)
		marble.BrickColor = BrickColor.Random()
		marble.Transparency = 0.45
		marble.Shape = Enum.PartType.Ball
		marble.Material = Enum.Material.SmoothPlastic
		local Velocity = Instance.new("BodyAngularVelocity",marble)
		local Hum = char:WaitForChild("Humanoid")
		local Weld = Instance.new("Weld")
		Weld.Parent = marble
		Weld.Part0 = HRP
		Weld.Part1 = marble
		Hum.PlatformStand = true
		Hum.Jump = false

		while wait() do
			marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 32,0,char.Humanoid.MoveDirection.x * -32)
			marble.BodyAngularVelocity.MaxTorque = Vector3.new(30000,30000,30000)
			if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
				marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
			end
		end
	end)
end)

Please note that I picked this code up off of a forum a few years back, so I’m not too educated on these types of games.

If you need any more specifics, please don’t hesitate to let me know.

Have you tried this?

And set the state to Physics maybe

Using Humanoid:SetStateEnabled() to turn off the Enum.HumanoidStateType.Jumping state (which prevents the player’s Character from being able to enter the Jumping state) is the way to go for this situation.

That method is recommended over setting JumpHeight / JumpPower to 0 as outlined on the documentation pages for Humanoid.JumpHeight and Humanoid.JumpPower:

Although setting this property to 0 will effectively prevent the humanoid from jumping, it’s recommended to disable jumping by disabling the Enum.HumanoidStateType.Jumping state through Humanoid:SetStateEnabled().


Example Implementations

Take note that this would need to be called from the client who is no longer allowed to jump (e.g. through a LocalScript that is being run by the player). If it is only called from the Server side, it won’t prevent the player from jumping.


Based on the code included in the original post, it seems like the player will always be inside the marble. If that’s the case, you could create a LocalScript with the following code and place it into the StarterCharacterScripts container so that it’ll immediately run every time the player’s Character respawns:

Example #1 (Jumping permanently turned off)

-- Example LocalScript Code #1
-- Placed into StarterCharacterScripts

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)


However, if you want to be able to decide when the player can or cannot jump throughout the course of gameplay (e.g. only prevent the player from jumping when they are in the marble but allow them to jump again when they exit the marble), you could use a RemoteEvent to communicate with the client so that the LocalScript can turn it on or off when desired.


For the second example to fully work, you’d call RemoteEvent:FireClient() from a server-sided Script whenever necessary, sending through true if you want the player to have the ability to jump, or false if you do not want the player to be able to jump.

  • Although just like the first example, the example code included below is what would be for a LocalScript in the StarterCharacterScripts container. This is what would be listening for the server to call RemoteEvent:FireClient().

Example #2 (Alternative implementation where the ability to Jump can be turned on / off)

-- Example LocalScript Code #2
-- Placed into StarterCharacterScripts

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JumpRemoteEvent = ReplicatedStorage:FindFirstChild("JumpRemoteEvent")

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
-- If you want, this can be turned off by default upon spawning, but then...

if JumpRemoteEvent then
    JumpRemoteEvent.OnClientEvent:Connect(function(newValue)
        Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, newValue)
--[[
Can call RemoteEvent:FireClient() from the server with a value of "true" or
"false", depending on if and when you want the player to be able to jump or not
--]]
    end)
end

Not sure if this is what you’re looking for … no jump

--LocalScript in StarterCharacterScripts 
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if humanoid.Jump then humanoid.Jump = false
	end
end)

Works well … kind of hackable.

Is there a way where I can execute this on the server? I wanna make everything Unhackable

How do I execute this on the server?

Note: This post was marked as the solution, but for anyone who reads through this in the future and jumps straight to the solution, the actual Luau code that you’d write in a LocalScript to turn off the ability to jump can be found in my initial reply to this thread:


*The rest of this post goes into detail about why it currently only works when the code is run via the client and not from the server-side:


(Everything from this point is what was included in the original version of this reply, before editing it to add the notes above)

As far as I understand, that’s not possible with the current, built-in physics and Character system because of how Network Ownership works, although it might be possible in the future.



With the current system, the player has Network Ownership over their Character by default, which means that the Client is the one in control over which HumanoidStateType they can enter. That’s the underlying reason for why I mentioned the following in my original reply:


Even the example code block from the Roblox Creator Hub makes use of Humanoid:SetStateEnabled() within a LocalScript:

The following sample will require a one second cooldown after a Humanoid has landed before it is able to jump again.

To try this sample, place it inside a LocalScript in StarterCharacterScripts.

LocalScript Example of a Jump Cooldown from the Roblox Creator Hub
-- LocalScript Example of a Jump Cooldown from the Roblox Creator Hub
local character = script.Parent

local JUMP_DEBOUNCE = 1

local humanoid = character:WaitForChild("Humanoid")

local isJumping = false
humanoid.StateChanged:Connect(function(_oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if not isJumping then
			isJumping = true
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		end
	elseif newState == Enum.HumanoidStateType.Landed then
		if isJumping then
			isJumping = false
			task.wait(JUMP_DEBOUNCE)
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		end
	end
end)


Another way to demonstrate that the Server does not have direct control over that is by having both the Server and Client listen for what HumanoidStateTypes the Character enters (by using Humanoid.StateChanged).

-- Example Server-sided code (placed in ServerScriptService)
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		
		local Humanoid = Character:WaitForChild("Humanoid")
		
		local detectedJumps = 0
		Humanoid.StateChanged:Connect(function(newState)
			print("Server-Script-detected: "..tostring(newState))
			
			if newState == Enum.HumanoidStateType.Jumping then
				detectedJumps += 1
				
				warn("\n\n\n Server Script detected the 'Jumping' state!")
				warn("Total number of times detected: "..tostring(detectedJumps).."\n\n\n")
			end
			
		end)
		
	end)
end)

(Test both of these at the same time)

-- Example LocalScript code (placed in StarterCharacterScripts)
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local detectedJumps = 0

Humanoid.StateChanged:Connect(function(newState)
	warn("LocalScript-detected: "..tostring(newState))
	
	if newState == Enum.HumanoidStateType.Jumping then
		detectedJumps += 1
		
		warn("\n\n\n LocalScript detected the 'Jumping' state!")
		warn("Total number of times detected: "..tostring(detectedJumps).."\n\n\n")
	end
end)

Upon running the code and jumping around, you’ll notice in the Output that it only ever displays Enum.HumanoidStateType.Jumping from the LocalScript and not the Server-sided Script.



However, you can still implement sanity checks on the server-side to lessen the likelihood that players try to tamper with the game and re-enable jumping when you want it to remain turned off (in this case, the movement validation section of that Roblox Creator Hub Guide would be the most relevant).

  • Although it might be a bit tricky if the marbles are able to roll over jump pads or fly off of ramps since you’d need a way to differentiate between those moments where the player uses the environment to gain height versus situations where upwards movement was caused by the player’s Character jumping.

How you’d go about designing the map to prevent jumping around from being an issue or implementing an anti-cheat for this in particular would vary depending on how advantageous jumping is during gameplay / how easy it’d be to detect it.

  • If it’s a marble obby game and there’s a gap somewhere that would be impossible for the player to cross without jumping, then you could place an invisible wall there or teleport them back if they try to cross it so that they are required to go the intended route.

I’m not sure of many other specific suggestions I’d have from this point since the possible measures you could implement would be dependent on what the intended gameplay is meant to be like.

If you’re still interested in looking for a more robust solution, I hope that there was enough useful info here to at least be a starting point for further research.

Ok, this is the solution, ty for responding to me!

1 Like