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

How do I clone and move a part with a script?

Asked by 7 years ago
Edited 7 years ago

I want to make a cannon shoot a cannonball which is a clone of the original. However, it is not cloning and if it did, it wasn't moving. This is one of the codes that I was using:

local Cannon = script.Parent
local CannonBody = Cannon.Union
local Cannonball = game.Workspace.Cannonball
local Wall = game.Workspace.Wall
local GameStart = false
local x = 14.5
local y = 3.312
local z = -72.5

function Cannonfire()
    if GameStart == true then
        local Clone = Cannonball:Clone()
        Clone.Position = Vector3.new(x, y, z)
        repeat
            wait(.5)
            Clone.Position = Vector3.new(x, y + .152, z - 1)
        until Wall.Touched == true
        if Wall.Touched == true then
            Clone:Destroy()
        end
    end
end
wait(5)
GameStart = true
Cannonfire()

What am I doing wrong and how do I fix it? Any help is appreciated!

0
Well, for one, GameStart is set to false TheScriptingBox 15 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Some problems I noticed were: - GameStart set to false

  • the part where you changed the position, it literally just did that, changed position. To make it shoot, you need a BodyVelocity. If you want to try the Vector3 way (not recommended), you would want to make it so that it ADDS Vector3, not changing it.
0
How would I be able to use BodyVelocity or to add Vector3? marioblast1244 113 — 7y
Ad

Answer this question