Applying AssemblyLinearVelocity

I am trying to set a parts AssemblyLinearVelocity, but it seems to do nothing, when printing the AssemblyLinearVelocity it returns the right number.

local part = workspace:WaitForChild("Part")
local UserInputService = game:GetService("UserInputService")

local Att = Instance.new("Attachment")
Att.Parent = part

part.AssemblyLinearVelocity = Vector3.new(0,100,0) -- this works

local function onInputBegan(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.E then
		part.AssemblyLinearVelocity = Vector3.new(0,100,0) -- this does not
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

It seems to work for me. Maybe you didnt anchor the part, or you didnt put it in a local script?

1 Like

I want it to move up when setting the velocity, when anchored it wont move, also it is in a local script.

1 Like

Well, I think the problem is that when it changes the AssemblyLinearVelocity, it doesn’t save. Meaning that if you print it as soon as it gets changed, it displays 0, 100, 0, but if you wait just a lil bit more, you’ll get 0, 0, 0.

I also found that this doesn’t happen in normal scripts, so try using normal scripts instead. Whether it’s through remote events, or something else.

1 Like

Is the script a LocalScript?

1 Like

yes, I’ve tried both. They seem to give the same result

1 Like

UserInputService only works in a LocalScript. LocalScripts should be parented in either StarterGui, StarterPlayerScripts, or StarterCharacterScripts. That could be why your script didn’t work as a LocalScript.

An alternative is setting the RunContext of a normal script to Client where you can parent the script in Workspace (and can also be parented the same as LocalScripts).

1 Like