For a projectile shot from a cannon I want it shot in a certain direction using a Vector3Value inserted under the model Cannon so that for each different instance of the cannon in my world, I don't have to jump into the code and set a new (x,y,z).
Instead I wish to use a Vector3Value named "Velocity" whose direct parent is the Model "Cannon"
local storage = game.ServerStorage while true do local cBall = storage.cannonBall:Clone() cBall.Parent = game.Workspace cBall.CFrame = CFrame.new(game.Workspace.Cannon.Barrel.Position) cBall.Velocity = Vector3.new(50,0,0) wait(2) end
This is the current code with the Vector3.new value there as a filler. How would I declare the Vector3Value as a variable so that the XYZ value that can be set in Explorer is used for the XYZ where the (50,0,0) is in the code
https://gyazo.com/3a6a04a25899ecb7b5695f0076eadb49 Here is a screenshot of the hierarchy I'm using with the "Shoot" script being the one I put in the code block.
Thank you for any help given!
~MBacon15
Assuming I'm understanding your question correctly, this should be a pretty simple task. We can simply declare the Vector3Value
a variable
the same way we would with any object, keeping in mind we'll still need the Value
property of it.
Here's a quick revision of your code:
-- I always declare my services with GetService at the beginning of all my scripts, but that's just me. local storage = game:GetService'ServerStorage' -- Make sure the Vector value is there before proceeding local velocity = script:WaitForChild'Velocity'.Value -- don't forget the Value property while true do local cBall = storage.cannonBall:Clone() cBall.Parent = workspace -- I also prefer using the built-in workspace variable, just to neaten your code a bit. cBall.CFrame = workspace.Cannon.Barrel.CFrame -- we could skip the process of creating a new CFrame and simply use the object's. cBall.Velocity = velocity -- assigning the value wait(2) end
Hope this helped, let me know if you have any questions.