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.
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...