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

Help on this clone then movement script?

Asked by
Mystdar 352 Moderation Voter
10 years ago
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.

0
The second part is text btw just glithced out as code Mystdar 352 — 10y

1 answer

Log in to vote
1
Answered by
KAAK82 16
10 years ago

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...
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? Mystdar 352 — 10y
0
Thanks btw! Mystdar 352 — 10y
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 KAAK82 16 — 10y
0
The outpur, please explain, you will have your tick and rating up when it fully works :) Mystdar 352 — 10y
View all comments (54 more)
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... KAAK82 16 — 10y
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 Mystdar 352 — 10y
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... KAAK82 16 — 10y
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! Mystdar 352 — 10y
0
edited... I made 2 just in case, cos I couldn't understand wat u were trying to tell me about the 'part' KAAK82 16 — 10y
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 Mystdar 352 — 10y
0
2nd one eh? try it now... KAAK82 16 — 10y
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! Mystdar 352 — 10y
0
Editited KAAK82 16 — 10y
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)? Mystdar 352 — 10y
0
And finally multiple can be spawned, so if someone is standing on the spawn button a lot are spawned. Mystdar 352 — 10y
0
if it's a Model use MoveTo() and or Rotation... use Rotation = CFrame.new() I think... KAAK82 16 — 10y
0
does the Arrow have 1 Part in it or more??? KAAK82 16 — 10y
0
More Mystdar 352 — 10y
0
hmmm... are they Welded? KAAK82 16 — 10y
0
4th line has a problem, again, Error Unable to cast double vector 3 Mystdar 352 — 10y
0
Not welded, no. Mystdar 352 — 10y
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 KAAK82 16 — 10y
0
Slight problem, I followed the guide and couldn't understand it, shall I uncopylock the arrow it has like 7 parts in it Mystdar 352 — 10y
0
u mean UnGroup the Model? KAAK82 16 — 10y
0
I mean make it an offical ROBLOX model for you to take then weld Mystdar 352 — 10y
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 KAAK82 16 — 10y
0
Is there a way to do it without welding? Mystdar 352 — 10y
0
well if u don't, the Main Part of ur Arrow will Rotate only and the rest will stay same using my method... KAAK82 16 — 10y
0
Wait, so I only need to weld for rotate and not movement? Mystdar 352 — 10y
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 KAAK82 16 — 10y
0
So I weld all the other parts to the main part of the arrow? Mystdar 352 — 10y
0
yeah somethin like that... KAAK82 16 — 10y
0
Right... And then it will work right? Oh and can you add the rotation script in please? Somewhere around the 4th line Mystdar 352 — 10y
0
try it KAAK82 16 — 10y
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! Mystdar 352 — 10y
0
for the Rotation u only need to give a Directory to a Part, so it's basically clone.Shaft KAAK82 16 — 10y
0
All the parts are welded to the shaft now, the welds are all children of the shaft, should it work now? Mystdar 352 — 10y
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! Mystdar 352 — 10y
0
dont forget about moving models, that it's MoveTo :P KAAK82 16 — 10y
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? Mystdar 352 — 10y
0
hmmm... wats line 12 supposed to mean??? wat Position??? KAAK82 16 — 10y
0
The script on the twelth line has a problem... and positioning it with moveto also doesn;t work Mystdar 352 — 10y
0
I mean wat does it mean, (something.position + Vector3.new(some other numbers here))??? KAAK82 16 — 10y
0
Look at the original code I wrote, it explains it Mystdar 352 — 10y
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??? KAAK82 16 — 10y
0
Because the first one puts it in place then the second one moves it Mystdar 352 — 10y
0
then remove the clone.Shaft.Position + so that ur only left with Vector3.new() cos am tired of editing tons of times... KAAK82 16 — 10y
0
But the move.CFrame = CFrame.new(-8.5, 3.5, -0.5) 'teleports' it but the second one smoothly moves it Mystdar 352 — 10y
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. KAAK82 16 — 10y
0
I don't understand that bit... Mystdar 352 — 10y
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) KAAK82 16 — 10y
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. Mystdar 352 — 10y
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 KAAK82 16 — 10y
0
Can you make it so it travels towards a part please? Mystdar 352 — 10y
0
If it helps, the part will be called Locator1 Mystdar 352 — 10y
0
k, so locator1, in Workspace, I'll try make a Script... KAAK82 16 — 10y
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... KAAK82 16 — 10y
0
did a Script for the Arrow, and changed the original Script... KAAK82 16 — 10y
Ad

Answer this question