How to set attachment of linear velocity in script

local function dash(actionName, InputState)
	if actionName == "dash" then
		if InputState == Enum.UserInputState.Begin then
			local keyPressed = game.UserInputService:GetKeysPressed()
				print(keyPressed)
				contains(keyPressed, Enum.KeyCode.W)
				if contains(keyPressed, Enum.KeyCode.W) == true then
					--Instance.new("Part", workspace)
					local att0 = Instance.new("Attachment", hrp)
					local linearVelocity = Instance.new("LinearVelocity", hrp)
					linearVelocity.Attachment = "att0"
				end
			end

			--if contain true
--print input object. keycode
-- if contain == true end holysht thats it
--		-- does order matter
	end
end

I want to set att0 as the attachment of linear velocity in script but I seem to be doing it wrong

The problem is that the attachment in the file explorer is not called “att0” that is the name of its variable in the script, as you can see its name is “attachment” that is because you did not give it a name, do this in the script:

att0.Name = "att0"

wait i just find others errors

No its because I typed “LinearVelocity.Attachment = xxx”, but apparently. its “LinearVelocity.Attachment0 = xxx”. (I forgot the zero). This is the solution

I tried your method but it still didnt work I dont know why. When i do "LinearVelocity.Attachment0 = “att0” " theres an error because it dosent take strings which makes sense. (the engine will really not recognize a string)

But when i do this instead “LinearVelocity.Attachment0 = att0” the engine takes it as a variable why is that so

first error: to refer to the attachment of a linearvelocity you do not say "linearVelocity.Attachment = “att0"”
instead you say:

"linearVelocity.Attachment0 = “att0"”

second mistake: you should not put quotes in the name of the object, because otherwise the game will not take it as an instance, instead of saying "linearVelocity.Attachment0 = “att0"” say “linearVelocity.Attachment0 = att0”

this is the correct way:

linearVelocity.Attachment0 = att0
1 Like

luv u bro onto the next problem when I put the linearvelocity force on a player it starts playing the walk animation

Ok let me think about it and see what happens now.

I need you to show me the area of the code responsible for reproducing the animation

oh wait, trying my own version of the script that also happened to me, when setting a speed in the linear velocity the character played the walking animation, wait while I see why

Theres none, no animation scripts no anything. It just plays the animation i dont really know why it might be automatic (like as in its in the roblox character code itself).

It might be because of the humanoid state

Exactly, I realized that the programming of the default Roblox animations works like this: when the player moves and the hipheight is touching the ground, the running or walking animation is activated, but if it is in the air and moving it does not activate that animation if not the fall animation is activated, to solve this I have already thought of several solutions, let me see which of them can work

But I need to know something, why is this a problem for you? Do you want, for example, to activate a different animation? Something like your own dash animation?

oh i forgot about animations its probably gonna solve this issue nvm

then you want to play a dash animation when linear velocity is activated

yo i have another problem when i jump and use it the player rotates like he does a frontflip. How do i stop the rotation?

You should program that the player cannot jump while dashing, I think you can do that by changing the jump height to 0 while dashing

I want the player to be able to jump though, do I just set the rotation? or is there a better method

I don’t think it’s a good habit to make a dash where you can jump while doing it.