Hey guys, I'm trying to make a homing rocket launcher. The actual problem is that the second script, the one that's supposed to be moved to the rocket, is not working. The first script used to be smashed too, but I realised I had to make it a localscript. Rocket LAUNCHER Script:
script.Parent.Equipped:connect(function (m) m.KeyDown:connect(function (key) if key:lower() == "q" then local p = m.Target if p:IsA("Part") then Rocket = Instance.new("Part", game.Workspace) Rocket.BrickColor = BrickColor.new("Bright red") Rocket.Size = Vector3.new(1,1,4) Mesh = script.Parent.Mesh:Clone() Mesh.Parent = Rocket Rocket.Position = script.Parent.Handle.Position + Vector3.new(0, 3, 0) RP = Instance.new("RocketPropulsion", Rocket) RP.Target = p RP:Fire() RP.CartoonFactor = 1 newScript = script.Explosion:Clone() newScript.Parent = Rocket newScript.Disabled = false RP.MaxThrust = 10000 RP.MaxSpeed = 1000 end end end) end)
And the script that goes into the ROCKET:
function GetDistance(Object1, Object2) return(Object1.Position - Object2.Position).magnitude end while true do script.Value.Value = (GetDistance(script.Parent, script.Parent.RocketPropulsion.Target)) if script.Value.Value > 100 then script.Parent.RocketPropulsion.MaxSpeed = 250 elseif script.Value.Value < 100 then script.Parent.RocketPropulsion.MaxSpeed = 125 elseif script.Value.Value < 50 then script.Parent.RocketPropulsion.MaxSpeed = 75 elseif script.Value.Value > 10 then script.Parent.RocketPropulsion.MaxSpeed = 25 elseif script.Value.Value < 10 then script.Parent.RocketPropulsion.MaxSpeed = 15 elseif script.Value.Value == 10 then script.Parent.RocketPropulsion.MaxSpeed = 20 end wait(.05) script.Parent.Touched:connect(function (hit) e = Instance.new("Explosion", hit) e.Position = hit.Position e.ExplosionType = "CratersAndDebris" e.BlastRadius = 10 script.Parent:Destroy() end) end script.Parent.Touched:connect(function (hit) e = Instance.new("Explosion", hit) e.Position = hit.Position e.ExplosionType = "CratersAndDebris" e.BlastRadius = 10 script.Parent:Destroy() end)
I'm not sure what I did wrong, so if anyone could tell me that would be great. Thanks in advance.
In my own experience (trying to develop a similar rocket system right now) the hardest part seems to be picking out the specific player. My idea was to use Mouse.Target to get the torso of the targeted character and then propel the rocket with a toned down BodyPosition. So maybe look over the targeting part a bit more. Also, I don't think you need the repeated "Touched" function inside the while loop, since you already have it outside the loop.