1

# "print()" Not printing the correct values?

Ok, so a little back story, I've been making this gun for months now, and so far it's been working great, a few problems but nothing that a little thinking cant help. However, I came across this one issue that is not making any sense to me. ("BV" is the variable for "BodyVelocity.Velocity")

while Bullet do

wait(5)

BV = Vector3.new(BV.X, 10,BV.Z)

end


Now, with this code you would expect that the Velocity of BV (The bullets Body Velocity), would have its Y value changed to 10, and so did I. Until I looked in Body Velocity directly and found that the Velocity is exactly the same, and Y did not change at all. So I decided to put some prints in my script to test it.

while Bullet do

print(BV.Y)

wait(5)

BV = Vector3.new(BV.X, 10,BV.Z)
print(BV)
end


However, (this is the part that really confuses me) even tho looking at the body velocity I know it has not changed, when I look in the output, I see that somehow Roblox is printing "10". So in essence, there is a discrepancy in what im printing and what the script actually is doing, help. I have looked at this for weeks, and I don't know what is happening. Also if there is any way to add pictures to one of these questions, Id loves, to better describe this problem.

Sincerely, An extraordinarily confused noob scripter

0
your printing it to console so it dosent run it 2012loluke 0 — 4mo

0

I tested this out myself and it appeared to be correct. I inserted a part into the workspace called Bullet, and made a script like the one above:

local Bullet = workspace:WaitForChild("Bullet")
local BV = Bullet:WaitForChild("BulletVelocity").Velocity

while Bullet do
print("Bullet Y Velocity: ")
print(BV.Y)
wait(5)
BV = Vector3.new(BV.X, 10, BV.Z)
print("Bullet Velocity: ")
print(BV)
end


And this printed out correctly. Each time print(BV) would result in (0, 10, 0), and print(BV.Y) would result in 10.

I think I see the discrepancy you were talking about now. When I click on "BulletVelocity", the BodyVelocity object in the "Bullet" part, the value hadn't changed. When I manually changed the value to (0, 10, 0), I noticed the part flew much faster.

In order to solve this, I would make BV a reference to the "BulletVelocity" object, rather than the velocity, like this:

local Bullet = workspace:WaitForChild("Bullet")
local BV = Bullet:WaitForChild("BulletVelocity")

while Bullet do
print("Bullet Y Velocity: ")
print(BV.Velocity.Y)
wait(5)
BV.Velocity = Vector3.new(BV.Velocity.X, 10, BV.Velocity.Z)
print("Bullet Velocity: ")
print(BV.Velocity)
end


But why did the first script not work?

Whenever you do something like this:

local part = workspace:FindFirstChild("Part")


The variable part is storing a reference to the part. Whenever I did this in the first script:

local BV = Bullet:WaitForChild("BulletVelocity").Velocity


I was not setting BV to a reference the velocity property; instead, it was simply returning the Vector3 value that was stored in BulletVelocity.Velocity. So whenever I changed BV, I was simply changing a Vector3 value that was disconnected from the object.

0
Oh my gosh, I feel like such a derp now. That did that trick, thanks :) generalYURASKO 99 — 4mo