Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

CFrame not working because Vector3 expected?

game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
player = game.Players.LocalPlayer
hum = player.Character

--[[function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.W then
		hum.Torso.Position = hum.Torso.Position + Vector3.new(0,0,5)
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)--]]

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.W then
		hum.Torso.CFrame = hum.Torso.CFrame + CFrame.new(0,0,5)
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

the commented part is the vector3 one that didnt have any errors, but detached me torso from the character. i wanted to use CFrame because i want the rest of the player to move with the body.

4 comments

1

CFrame.new requires a Vector3 value for its first argument. All you have to do is put 0,0,5 into a Vector3 value.

0

i did, and nothing.

2

Also, CFrame is a matrix essentially. You can't add them, but you can multiply them.

0

thank you

1 answer

✓ Accepted answer

You can't add CFrames, only multiply them.

game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
player = game.Players.LocalPlayer
hum = player.Character

--[[function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.W then
        hum.Torso.Position = hum.Torso.Position + Vector3.new(0,0,5)
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)--]]

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.W then
        hum.Torso.CFrame = hum.Torso.CFrame * CFrame.new(0,0,5) -- Can't Add CFrames only multiply them.
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 comment

0

thanks dude, but M39a9am3R already helped with this, if you would navigate yourself to the comments on my question, you would see that the aforementioned M39a9am3R fixed the problem

This discussion is preserved as it was. New answers, comments, and votes are closed.