Hello everyone!
I’ve come across this one issue where it’s very confusing and odd, and may in fact be a ROBLOX bug…
I was coding in some custom vehicle movement system, and I was using BodyVelocity as the throttle. However, upon setting its Velocity
to body.CFrame.LookVector * speed
, it just gives me this error:
Velocity cannot be assigned to
Yes, you saw it right. It doesn’t even give me what it can’t be assigned to, which makes this issue nearly 15x harder to figure out.
FYI: I’m using a server script.
Here’s my code:
if forward and not backward then
bodyVelocity.Velocity = body.CFrame.LookVector * speed
elseif backward and not forward then
bodyVelocity.Velocity = body.CFrame.LookVector * -(speed/2)
elseif (forward and backward) or (not forward and not backward) then
bodyVelocity.Velocity = body.CFrame.LookVector * 0
end
That’s why I confronted you guys, so any help is appreciated :)))
Try
Vector3.new(body.CFrame.LookVector * speed)
Nope, still gives the same error…
Is that all of the script?
–X
No, it’s just the portion where the error is coming from.
Can I see the whole script?
–X
Sure thing:
local seat = script.Parent
local occupiedPlayer = nil
local directionRemote = seat.SendDirections
local body = seat.Parent.Mass
local car = seat.Parent
local FLattachment = body.AttachmentFL
local FRattachment = body.AttachmentFR
local bodyVelocity = body.Velocity
local speed = 30
local function onDirectionsEvent(player, packet)
local forward = packet["Forward"]
local backward = packet["Backward"]
local left = packet["Left"]
local right = packet["Right"]
if player then
-- Turning stuff
if left and not right then
FLattachment.Orientation = Vector3.new(0,30,-90)
FRattachment.Orientation = Vector3.new(0,30,-90)
elseif right and not left then
FLattachment.Orientation = Vector3.new(0,-30,-90)
FRattachment.Orientation = Vector3.new(0,-30,-90)
elseif (right and left) or (not right and not left) then
FLattachment.Orientation = Vector3.new(0,0,-90)
FRattachment.Orientation = Vector3.new(0,0,-90)
end
-- Movement stuff
if forward and not backward then
bodyVelocity.Velocity = body.CFrame.LookVector * speed
elseif backward and not forward then
bodyVelocity.Velocity = body.CFrame.LookVector * -(speed/2)
elseif (forward and backward) or (not forward and not backward) then
bodyVelocity.Velocity = body.CFrame.LookVector * 0
end
end
end
directionRemote.OnServerEvent:Connect(onDirectionsEvent)
Excuse my weird way of sending directions through remote events.
body.Velocity
is a BodyVelocity instance right?
Yes, bodyVelocity.Velocity
is the thing that handles the moving.
You need to say body.Velocity
not bodyVelocity.Velocity
the bodyVelocity
variable is the velocity value of the body velocity.
2 Likes
OHHHHHHHHHHHH MY GOD!!
I never realized that!
Thank you so much my man!!!
1 Like
No problem. It is very, very easy to start thinking on a bigger scale about weird errors when the whole time is was something so simple. I am glad I could help!
1 Like