Move Direction Weird

Hello, I am making a marble game and I’ve got the marble spawning thing and movement working. However there is 1 tiny problem with the movement. When you move, the ball moves to the left or right, but you only press W and S. No errors in output. Anyone know why this is happening? Thanks.

--Physics code
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local character = script.Parent
local hum = character:WaitForChild("Humanoid")
local marble = character:WaitForChild("Marble")
local angularVelocity = marble:WaitForChild("BodyAngularVelocity")

local params = RaycastParams.new()
params.FilterDescendantsInstances = {}
params.FilterType = Enum.RaycastFilterType.Blacklist
params.RespectCanCollide = true

local lastJump = 0

hum.PlatformStand = true

RunService.Stepped:Connect(function(_, dt)
	local moveDirection = hum.MoveDirection
	angularVelocity.AngularVelocity = Vector3.new(moveDirection.z * 32,0,moveDirection.x * -32)
	angularVelocity.MaxTorque = Vector3.new(20000,20000,20000)
	if hum.MoveDirection == Vector3.new(0,0,0) then
		angularVelocity.MaxTorque = Vector3.new(0,0,0)
	end

	if hum.Jump and (time() - lastJump > 1/3) then
		local result = workspace:Raycast(marble.Position, Vector3.new(0, -marble.Size.Y / 2 - 1, 0), params)
		if result and result.Instance then
			print(result.Instance)
			lastJump = time()
			marble.AssemblyLinearVelocity = marble.AssemblyLinearVelocity * Vector3.new(1, 0, 1) + Vector3.new(0, 75, 0)
		end
	end
end)

local function PlayerAdded(player)
	local function characterAdded(character)
		local filter = params.FilterDescendantsInstances
		table.insert(filter, character)
		params.FilterDescendantsInstances = filter
	end
	player.CharacterAdded:Connect(characterAdded)

	local function characterRemoving(character)
		local filter = params.FilterDescendantsInstances
		table.remove(filter, table.find(filter, character))
		params.FilterDescendantsInstances = filter
	end
	player.CharacterRemoving:Connect(characterRemoving)

	if player.Character then
		characterAdded(player.Character)
	end
end

for _, player in Players:GetPlayers() do
	PlayerAdded(player)
end
Players.PlayerAdded:Connect(PlayerAdded)

Video:
robloxapp-20221223-1731288.wmv (5.4 MB)
If you don’t wanna download the video, lmk and ill convert it to an mp4. Just takes alot of time lol.

table.insert or table.remove does not work on RaycastParams.FilterDescendantsInstances anymore

1 Like

Alternative way to fix this

RaycastParam.FilterDescendantsInstances = {unpack(RaycastParam.FilterDescendantsInstances),object}
1 Like