Marble moves with player, but doesn't jump

hi, i’ve got this marble that moves as the player moves, but it doesn’t jump. how can i make the player be able to jump, too? also, can i make the ball roll, keeping the player standing? thank you ^^

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

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

if you also know how to increase the speed let me know :slight_smile:

1 Like

Whats the purpose of the while loop feeding the BodyAngularVelocity if the sphere is welded to the HRP?

What doesnt jump? If the ball is welded to HRP, it jumps along with the character

Increase the speed of the player?
Character.Humanoid.WalkSpeed = 50

1 Like

To make the player able to jump, you can add the following code inside the while loop:

if HRP.Velocity.Y == 0 and Hum.Jump then -- check if the player is on the ground and trying to jump 
HRP.Velocity = Vector3.new(HRP.Velocity.X, 50, HRP.Velocity.Z) -- add an upward velocity to the player 
end

To make the ball roll while keeping the player standing, you can add the following code inside the while loop:

HRP.Velocity = Vector3.new(marble.BodyAngularVelocity.AngularVelocity.X, HRP.Velocity.Y, marble.BodyAngularVelocity.AngularVelocity.Z) -- set the player's velocity to match the ball's angular velocity

This will make the player move in the same direction as the ball is rolling, while still being able to jump.

If you want to increase the speed of the ball, you can try increasing the values of the marble.BodyAngularVelocity.AngularVelocity vector. For example, you can try changing the values to Vector3.new(char.Humanoid.MoveDirection.z * 64,0,char.Humanoid.MoveDirection.x * -64) to double the speed. You can also try increasing the marble.BodyAngularVelocity.MaxTorque vector to allow the ball to reach higher speeds.

is this the right way?

		while true do
			wait()
			if Hum.Jump then -- check if the player is on the ground and trying to jump 
				HRP.Velocity = Vector3.new(HRP.Velocity.X, 50, HRP.Velocity.Z) -- add an upward velocity to the player 
			end
			HRP.Velocity = Vector3.new(marble.BodyAngularVelocity.AngularVelocity.X, HRP.Velocity.Y, marble.BodyAngularVelocity.AngularVelocity.Z) -- set the player's velocity to match the ball's angular velocity
			marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 64,0,char.Humanoid.MoveDirection.x * -64)
			marble.BodyAngularVelocity.MaxTorque = Vector3.new(10000,10000,10000)
			if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
				marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
			end
		end

If the “marble” still welded by a Weld to the HRP that will never work, maybe a different constraint? a ball socket?

thank you, how can i make the ball roll?

Use what @N3F1R told you, just unweld the marble, and fuse it to character with a different constraint

This code will allow the player to jump while inside the ball, but it will not make the ball roll while the player is standing on it.

To make the ball roll while the player is standing on it, you will need to use a JointInstance, such as a Motor6D or BallSocket. You will also need to update the ball’s position and orientation using the JointInstance’s parameters.

Here is an example of how you can modify the code to achieve this:

local Motor6D = Instance.new("Motor6D")
Motor6D.Part0 = HRP
Motor6D.Part1 = marble
Motor6D.C0 = CFrame.new(0, 0, 0)
Motor6D.C1 = CFrame.new(0, 0, 0)
Motor6D.Parent = char

while true do
	wait()
	if Hum.Jump then -- check if the player is on the ground and trying to jump
		HRP.Velocity = Vector3.new(HRP.Velocity.X, 50, HRP.Velocity.Z) -- add an upward velocity to the player
	end
	-- update the ball's position and orientation using the Motor6D's parameters
	marble.CFrame = Motor6D.C1
	marble.BodyAngularVelocity.AngularVelocity = Motor6D.AngularVelocity
	-- update the Motor6D's target parameters based on the player's movement direction
	Motor6D.C0 = CFrame.new(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
	Motor6D.C1 = CFrame.new(char.Humanoid.MoveDirection * 5, char.Humanoid.MoveDirection)
end

This code will update the ball’s position

Seems like BodyAngularVelocity is depracated isnt?

1 Like

it doesn’t work for me :(, maybe i’m doing it wrong. can you send the mix of my script and your fixed part?

The mix would be like this, but, BodyAngularVelocity is deprecated and should not be used, plus AngularVelocity is not a valid member of Motor6D

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local HRP = char:WaitForChild("HumanoidRootPart")
		local marble = Instance.new("Part")
		marble.Size = Vector3.new(8,8,8)
		marble.BrickColor = BrickColor.Random()
		marble.Transparency = .5
		marble.Shape = Enum.PartType.Ball
		marble.Parent = char
		marble.Material = Enum.Material.SmoothPlastic
		local Velocity = Instance.new("BodyAngularVelocity")
		Velocity.Parent = marble
		local Hum = char:WaitForChild("Humanoid")
		
		local Motor6D = Instance.new("Motor6D")
		Motor6D.Part0 = HRP
		Motor6D.Part1 = marble
		Motor6D.C0 = CFrame.new(0, 0, 0)
		Motor6D.C1 = CFrame.new(0, 0, 0)
		Motor6D.Parent = char

		while true do
			wait()
			if Hum.Jump then -- check if the player is on the ground and trying to jump
				HRP.Velocity = Vector3.new(HRP.Velocity.X, 50, HRP.Velocity.Z) -- add an upward velocity to the player
			end
			-- update the ball's position and orientation using the Motor6D's parameters
			marble.CFrame = Motor6D.C1
			marble.BodyAngularVelocity.AngularVelocity = Motor6D.AngularVelocity
			-- update the Motor6D's target parameters based on the player's movement direction
			Motor6D.C0 = CFrame.new(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
			Motor6D.C1 = CFrame.new(char.Humanoid.MoveDirection * 5, char.Humanoid.MoveDirection)
		end
	end)
end)

so basically this code won’t work?
edit: just tested it and no, it doesnt work

Oh sorry my bad
To set the angular velocity of the marble, you can use the AngularVelocity property of the BodyVelocity object. You can also use the MaxTorque property to set the maximum torque that can be applied to the part.

Here’s an example of how you can modify your code to use the BodyVelocity object instead of BodyAngularVelocity :

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local HRP = char:WaitForChild("HumanoidRootPart")
		local marble = Instance.new("Part")
		marble.Size = Vector3.new(8,8,8)
		marble.BrickColor = BrickColor.Random()
		marble.Transparency = .5
		marble.Shape = Enum.PartType.Ball
		marble.Parent = char
		marble.Material = Enum.Material.SmoothPlastic
		local velocity = Instance.new("BodyVelocity")
		velocity.Parent = marble
		local Hum = char:WaitForChild("Humanoid")
		local Weld = Instance.new("Weld")
		Weld.Parent = marble
		Weld.Part0 = HRP
		Weld.Part1 = marble
		Weld.C0 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
		Weld.C1 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)

		-- This code will make the player jump when they press the space bar
		player.KeyDown:Connect(function(key)
			if key == "space" then
				Hum:Jump()
			end
		end)

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

it behaves the same as the previous code :frowning:

Look into console and check what errors it gives

Idk, the code sounds like something that chat.openai.com would do :sweat_smile:

If @Lushisnothere would be already using a Motor6D to fuse the ball and the char, I dont see the need to use any Physics mover, wouldnt be enough just to rotate the Motor6D according with the speed of the character?

how to do that? this seems a pretty hard topic to solve

I think its not that hard to accomplish, just some testing, but I would think if its really needed that the ball spins, being semitransparent, not having texture, its kinda useless to make it spin cause its not possible to notice if it does or not

it should become a fishbowl, that’s why i need it to spin

1 Like

i know i shouldn’t ask this, but do you mind checking if you have the solution to this?