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

Why can't I set the X of Velocity in BodyVelocity to the Value of an IntValue?

Asked by 9 years ago

The error occurred in this script;

while true do
    if script.Parent.Parent.Parent.Parent.Speed.Start.Value == true then
        script.Parent.velocity.X = script.Parent.Parent.Parent.Parent.Speed.Speed.Value
    else
        script.Parent.velocity.X = 0
    end
    wait()
end

the second to last Speed in script.Parent.velocity.X = script.Parent.Parent.Parent.Parent.Speed.Speed.Value is the Intvalue, and the one before that is a model called Speed. Also, Start is a BoolValue in the model Speed.

But why doesn't this work?

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that you're trying to individually manipulate the X axis - You can't do this. The Individual X, Y, and Z axis scales are read-only. Meaning that you can only take information from them, not assign information to them.


So to fix, you need to assign the velocity property with a Vector3 on all axises at the same time.


Also, I suggest you use the Changed event to set the property, rather than a while loop, it's much more efficient.


local val = script.Parent.Parent.Parent.Parent.Speed

val.Speed.Changed:connect(function(change)
    if val.Start.Value == true then
        script.Parent.velocity = Vector3.new(change,0,0)
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

You can't directly set those values. You have to set the full thing for example you can't do:

part.Position.X = 6

you would have to do

part.Position = Vector3.new(6, part.Position.Y, part.Position.Z)

I'm not sure exactly why this is but I believe has to do with them being read only or something similar.

I hope you can apply this to your code. If you need help doing so, ask.

0
Still having trouble trying to fix it, that didn't really help me much alex_ander 163 — 9y

Answer this question