Moving a part with collision problem

Hi, i’m having a problem with this Part Movement system. Basically, i want to move a simple object with userInputService, and that’s fine, but the problem comes with collisions. I want the object to collide with other parts, but it just goes through everything… I tried setting a collision group to the object and the parts to collide with, but nothing. Could you guys help me please? It would be very appreciated :slight_smile:!

Script: (StarterPlayerScripts)

local Input = game:GetService("UserInputService")

local cube = game.Workspace.Cube

local moveX = 0.5
local moveY = 0.5
local waitTime = 0.01

local inputLeft = script.inputLeft
local inputRight = script.inputRight
local inputUp = script.inputUp
local inputDown = script.inputDown

local left = false
local right = false
local up = false
local down = false

Input.InputBegan:Connect(function(input, gameProcessedEvent)
	while wait() do

		if Input:IsKeyDown(inputRight.Value) then
			right = true
		else
			right = false
		end

		if Input:IsKeyDown(inputLeft.Value) then
			left = true
		else
			left = false
		end

		if Input:IsKeyDown(inputUp.Value) then
			up = true
		else
			up = false
		end

		if Input:IsKeyDown(inputDown.Value) then
			down = true
		else
			down = false
		end

	end
end)


while wait(waitTime) do
	
	cube.Orientation = Vector3.new(0, 0, 0)

	if right == true then
		cube.Position = Vector3.new(cube.Position.X + moveX, 2, cube.Position.Z)
	end

	if left == true then
		cube.Position = Vector3.new(cube.Position.X - moveX, 2, cube.Position.Z)
	end

	if up == true then
		cube.Position = Vector3.new(cube.Position.X, 2, cube.Position.Z - moveY)
	end

	if down == true then
		cube.Position = Vector3.new(cube.Position.X, 2, cube.Position.Z + moveY)
	end

end

Here’s a small video:

This is because changing the part’s position will only do just that. Now you could code a whole physics system, and in some cases that might be worth it, but it might be easiest to just use Roblox’s physics. Make sure the part is unanchored, then use whichever force type works best for your type of movement.

i’ve just unanchored it and now it kinda “works”, i mean it doesn’t for the first 10 / 20 seconds, then it starts to collide with parts

You can continue with that if you want, but I’d recommend coding it properly. The problem with your method is it kinda follows the concept of “it just works”, until it doesn’t. If Roblox changes how that interaction works, it will break your movement system.

what would you suggest me to do?

I would suggest either coding a collision system or using Roblox’s physics system as I said above:

“Roblox’s Physics system” do you mean like body positions and stuff like that?

Maybe not BodyPositions, but other forces of that nature. Such as BodyForce or BodyVelocity. Each work in different ways, so you’ll have to experiment with each until you find the ones that work best.

Ok so, i’ve tried using your advice but it didn’t work… ('cause i’m bad with body movers)… But i got it to work by creating a new Instance Part and resize it when the player joins. Thanks anyway for your help :slight_smile:!

1 Like

I think answering after three years is not quite right, but I was also looking for an answer to the same question and found another solution, and maybe it will help someone. You just need to set network owner to the player, when you resize part after player joins, player starts to be the owner of the part!

game.Workspace.Сube:SetNetworkOwner(game:GetService("Players").LocalPlayer)