Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

CFrame not working because Vector3 expected?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
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.

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. M39a9am3R 3210 — 8y
0
i did, and nothing. theCJarmy7 1293 — 8y
2
Also, CFrame is a matrix essentially. You can't add them, but you can multiply them. M39a9am3R 3210 — 8y
0
thank you theCJarmy7 1293 — 8y

1 answer

Log in to vote
-1
Answered by 8 years ago

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)

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 theCJarmy7 1293 — 8y
Ad

Answer this question