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

Help on this clone then movement script?

function onTouched(hit)
	 if hit.Parent:findFirstChild("Humanoid") then -- Verify that a actual player hit it
local clone = game.Lighting.Arrow:clone()
	move = script.Parent.Parent.Arrow
	move.CFrame = CFrame.new(-8.5, 3.5, -0.5)
Arrow = script.Parent -- Object Tree location of part
	speed = .1 -- Speed of the movements, the lower the number, the faster and more smooth
	distance = 10 --The distance to move along the axis
	timestorun = distance * 10 -- Times to run, don't change this as it allows for smooth transitions
	for i = 1, timestorun  do -- i represents the index or current position of the loop, it starts at one and goes to whatever the times to run is, meaning it will run that many times
	    wait(speed) -- Wait for the designated speed time
	    part.CFrame = CFrame.new(part.Position + Vector3.new(0.1,0,0)) -- Change the CFrame by 0.1 to allow for a smooth transition
	end -- End the loop
	end -- End the first function
    end
script.Parent.Touched:connect(onTouched)
In this code when a player touches a brick called: Part     It will clone the part: Arrow   from the lighting then teleport it to a position and finally it moves 10 studs along the X axis, but it doesn't work when testing in play solo (and on its actual ROBLOX game) it has a problem with the 4th line saying it is not in the workspace. 
Please annotate any changes made.

Thank you in advance.

1 comment

0

The second part is text btw just glithced out as code

1 answer

✓ Accepted answer

u said

clone = game.Lighting.Arrow:clone()

then use it, not

move = script.Parent.Parent.Arrow

u dont need that line, use 'clone'

clone.CFrame

cos I don't see u using the Variable clone :/

function onTouched(hit)
     if hit.Parent:findFirstChild("Humanoid") then -- Verify that a actual player hit it
local clone = game.Lighting.Arrow:clone()
    clone.CFrame = CFrame.new(-8.5, 3.5, -0.5) --See? u didn't need the Variable 'move' just use the Cloned Part as the Part, else it's not used yet, cos u gotta give it it's Parent and stuff...
clone = script.Parent -- Object Tree location of part
    speed = .1 -- Speed of the movements, the lower the number, the faster and more smooth
    distance = 10 --The distance to move along the axis
    timestorun = distance * 10 -- Times to run, don't change this as it allows for smooth transitions
    for i = 1, timestorun  do -- i represents the index or current position of the loop, it starts at one and goes to whatever the times to run is, meaning it will run that many times
        wait(speed) -- Wait for the designated speed time
        game.Workspace.part.CFrame = CFrame.new(game.Workspace.part.Position + Vector3.new(0.1,0,0)) -- Change the CFrame by 0.1 to allow for a smooth transition
    end -- End the loop
    end -- End the first function
    end
script.Parent.Touched:connect(onTouched)

else if the 'part' is the Arrow then

script.Parent.Touched:connect(function(hit) --It's better to have it this way if ya need to remove the Arrow later
     if hit.Parent:findFirstChild("Humanoid") then
local clone = game.Lighting.Arrow:clone()
    clone:MoveTo(Vector3.new(-8.5, 3.5, -0.5)) --I use MoveTo for Models
	clone.Shaft.Rotation = CFrame.new(ur Angles here)
clone.Parent = script.Parent
    speed = .1
    distance = 10
    timestorun = distance * 10
    for i = 1, timestorun  do
        wait(speed)
        clone.RocketPropulsion:fire() --Find the cloned Arrow's RocketPropulsion and Activates it
	game.Debris:AddItem(clone, 10) --Change clone to other Names if u ever need to, change 10 to Seconds in how much it's removed
    end
    end
    end)

In an Arrow

local RP = Instance.new('RocketPropulsion', script.parent)
RP.Target = game.Workspace.locater1 --change to ur Part Name if u changed it...
RP.MaxSpeed = 1000 --Change to ur Speed
RP.CartoonFactor = 0 --this is for the Arrow Pointing forward to the Target, change to ur needs if 0 doesn't suit u...

58 comments

0

When I clone the arrow, if there is a damage script in it would that be cloned too? Also thanks, you solved the problem on the 4th line but now the 11th line is acting up, can you resolve this please?

0

Thanks btw!

0

can I have the Output, and yes, it clones IT and ALL it's CHILDREN... Also, if I help fully don't forget to Click the 'Answered' Button

0

The outpur, please explain, you will have your tick and rating up when it fully works :)

0

The Output, wat it says... click on top View, look for Output and click it, and then Run the Code, copy and Paste the Error here...

0

[Red X] Error Attempt to index global 'part' (a nil value) Part is the block that contains these scripts the error is the 11th line

0

u diddn't define Part, if it's the arrow ur talkin about, just use the 'clone; variable from above, else do game.Workspace and stuff at the top...

0

Please can you write out the script as a new answer, when that works your answer will be accepted and a positive rating too!

0

edited... I made 2 just in case, cos I couldn't understand wat u were trying to tell me about the 'part'

0

I done the second script and the bit that moved was the part not the arrow, the arrow didn't even spawn, it is in the Lighting before you ask

0

2nd one eh? try it now...

0

THanks that is awesome however can you add in a script that removes the arrow at the end (So put in wait(10) so 10 seconds after it had reached its desination remove it. Also the part can be clicked multiple times!

0

Editited

0

I thank you very much for your efforts however there are three small problems: Firstly it doesn't work with models (If arrow is a model it doesn't work) the output on the 4th line is Error CFrame is not valid membr of Model (The model is called Arrow) secondly how would you set its rotation when spawned and what line would you put it on? Would it be like clone.Rotation=Rotation.new (0, 0, 0)?

0

And finally multiple can be spawned, so if someone is standing on the spawn button a lot are spawned.

0

if it's a Model use MoveTo() and or Rotation... use Rotation = CFrame.new() I think...

0

does the Arrow have 1 Part in it or more???

0

More

0

hmmm... are they Welded?

0

4th line has a problem, again, Error Unable to cast double vector 3

0

Not welded, no.

0

k, am editing the Answer... also, Weld the Arrow, just put a Weld script into the Arrow http://wiki.roblox.com/index.php/Welds

0

Slight problem, I followed the guide and couldn't understand it, shall I uncopylock the arrow it has like 7 parts in it

0

u mean UnGroup the Model?

0

I mean make it an offical ROBLOX model for you to take then weld

0

oh lol... if u dont want them to go into eachother do the last one on the Wiki... I just don't have the right time and my Studio Glitches like hell

0

Is there a way to do it without welding?

0

well if u don't, the Main Part of ur Arrow will Rotate only and the rest will stay same using my method...

0

Wait, so I only need to weld for rotate and not movement?

0

Weld them all so u can take the main Part and Rotate it, cos if they're Welded, the Parts should move with the Main Part

0

So I weld all the other parts to the main part of the arrow?

0

yeah somethin like that...

0

Right... And then it will work right? Oh and can you add the rotation script in please? Somewhere around the 4th line

0

try it

0

Okay so, i'm going to weld all the parts to a part in the arrow called Shaft, edit your script so this will work please, maybe only move the part shaft and the others will move with it!

0

for the Rotation u only need to give a Directory to a Part, so it's basically clone.Shaft

0

All the parts are welded to the shaft now, the welds are all children of the shaft, should it work now?

0

I tried it and I got the same problem as eariler with the 12th line saying Error Position is not a valid part of the model. Could you edit the script so after the arrow is spawned could you make the shaft move to the postion then rotate the shaft then move the shaft with that script above, thanks!

0

dont forget about moving models, that it's MoveTo :P

0

The moveto bit doesn't work (Positioning it) no output there it just doesn't work, the rotation part also doesn't work and the 12th line still doesn't work, shall I uncopylock the place so you can try and solve it?

0

hmmm... wats line 12 supposed to mean??? wat Position???

0

The script on the twelth line has a problem... and positioning it with moveto also doesn;t work

0

I mean wat does it mean, (something.position + Vector3.new(some other numbers here))???

0

Look at the original code I wrote, it explains it

0

I know, I'm asking for wat :P cos y would u need to take the Arrows Position and add on some other Position???

0

Because the first one puts it in place then the second one moves it

0

then remove the clone.Shaft.Position + so that ur only left with Vector3.new() cos am tired of editing tons of times...

0

But the move.CFrame = CFrame.new(-8.5, 3.5, -0.5) 'teleports' it but the second one smoothly moves it

0

use RocketPropulsion... u can set were u want it to move and at wat Speed... http://wiki.roblox.com/index.php?title=How_To_Make_Homing_Objects.

0

I don't understand that bit...

0

sry if that link nothing in it... just realiszed that... http://wiki.roblox.com/index.php?title=How_To_Make_Homing_Objects. so just remove the 2nd Position bit... and then inside the Arrow itself put a Script with the Instructions from the link I gave u... then ur Arrow will move towards the Target (wether it be a Brick or a Person)

0

If you have a better way of doing what my script does, then please put it in a new script under the second one.

0

depends... is it gonna go after a Player or a Part (cos the Arrow will follow Player all the way, werever he goes), i it's a Part, it will follow the Part(it can be Anchored and Transparent and CanCollide = false) and then u can call the :Destroy() function

0

Can you make it so it travels towards a part please?

0

If it helps, the part will be called Locator1

0

k, so locator1, in Workspace, I'll try make a Script...

0

also, while am at it, Thumbs Up for me, cos am so tired o Posting Comments all the Time here and trying to make the Script for u while I need to Think about my Game...

0

did a Script for the Arrow, and changed the original Script...

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