Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

1 comment

0

Well, for one, GameStart is set to false

1 answer

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.

1 comment

0

How would I be able to use BodyVelocity or to add Vector3?

This discussion is preserved as it was. New answers, comments, and votes are closed.