I need help with my marble ball system

If you don’t know what a ‘marble ball system’ is, its basically the first result when you google ‘marble ball system roblox’.

Basically the problem is that i’m trying to figure out how i’d go about flinging the ball or drastically changing its velocity when its touched by a part.

Also I would want to make a system where when the ball touches a “air vent” the ball levitates up. Wondering if anybody can help me on this?

2 Likes

Here’s an article that describes a system similar to the one you are describing. How do I make a Marble Movement System? - #4 by G8Max , Whenever the ball goes into the area that you want to affect the ball you can edit the bodyforce or thrust in the direction that you need the ball to go.

2 Likes

I’ll look into it, honestly ive spent all yesturday trying to find a solution on what I should do. Rn I have a server side script running a loop per player to detect when W,A,S,D keys are pressed to judge which direction they are going. Im sure it has something to do with that but I dont see how I could both keep that while making what I want to make

1 Like

It would be best to use a client-sided script to recognize input and then communicate through Remote Events any server-sided actions you need taken care of.

1 Like

rn on the client side, i got it like this for the fling. But like, it stops the controls but doesnt actually fling the ball

local active = true
local plr = game.Players.LocalPlayer

local succ,err = pcall(function()
	local marble = plr.Character:FindFirstChild('MarbleBall')
	marble.Touched:Connect(function(h)
		if h.Name == 'TargetLaunch' then
			print('ran')
			active = false
			wait(.2)
			plr.Character.HumanoidRootPart.Velocity = Vector3.new(math.random(-1000,1000), 1000,math.random(-1000,1000))
			wait(1)
			active = true
		end
	end)
end)


while true and active == true do
	local succ,err = pcall(function()
		wait()
		local char = plr.Character
		local marble = plr.Character:FindFirstChild('MarbleBall')
		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

nvm i asked chatgpt and it said to do this and it worked, W chat

local plr = game.Players.LocalPlayer

while true do
	local succ, err = pcall(function()
		wait()
		local char = plr.Character
		local marble = char:FindFirstChild('MarbleBall')

		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)

	-- Touched event handling
	local succ,err = pcall(function()
		local char = plr.Character
		local marble = char:FindFirstChild('MarbleBall')

		if marble then
			marble.Touched:Connect(function(otherPart)
				-- Check if the touched part is not the character itself
				if otherPart.Name == 'TargetLaunch' then
					-- Apply a force or change velocity to simulate the flinging effect
					local flingForce = Vector3.new(0, 5000, 0)
					--marble:SetNetworkOwner(nil)  -- Optional: release ownership if necessary
					marble:ApplyImpulse(flingForce)
				end
			end)
		end
	end)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.