HI I am trying to make my rocket (classic roblox rocket) destroy parts that have been spawned and moved to a specific part in the work space but when any object is moved the rocket ignores it and goes straight through it! I have been trying to change network ownership, look for articles that relate to mine (none), but I haven’t been able to find the problem and I don’t know what to do.
The rocket script is split into 2 scripts
- the server script that handles the tool events and spawns the rocket part
- the script that controls the rocket part and its collisions / explosions
--SCRIPT 1
-----------------
--| Constants |--
-----------------
local GRAVITY_ACCELERATION = workspace.Gravity
local RELOAD_TIME = 3 -- Seconds until tool can be used again
local ROCKET_SPEED = 60 -- Speed of the projectile
local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
-----------------
--| Variables |--
-----------------
local DebrisService = game:GetService('Debris')
local PlayersService = game:GetService('Players')
local MyPlayer
local Tool = script.Parent
local ToolHandle = Tool:WaitForChild("Handle")
local MouseLoc = Tool:WaitForChild("MouseLoc",10)
local RocketScript = script:WaitForChild('Rocket')
local SwooshSound = script:WaitForChild('Swoosh')
local BoomSound = script:WaitForChild('Boom')
--NOTE: We create the rocket once and then clone it when the player fires
local Rocket = Instance.new('Part') do
-- Set up the rocket part
Rocket.Name = 'Rocket'
Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
Rocket.Size = ROCKET_PART_SIZE
Rocket.CanCollide = true
-- Add the mesh
local mesh = Instance.new('SpecialMesh', Rocket)
mesh.MeshId = MISSILE_MESH_ID
mesh.Scale = MISSILE_MESH_SCALE
-- Add fire
local fire = Instance.new('Fire', Rocket)
fire.Heat = 5
fire.Size = 2
-- Add a force to counteract gravity
local bodyForce = Instance.new('BodyForce', Rocket)
bodyForce.Name = 'Antigravity'
bodyForce.Force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
-- Clone the sounds and set Boom to PlayOnRemove
local swooshSoundClone = SwooshSound:Clone()
swooshSoundClone.Parent = Rocket
local boomSoundClone = BoomSound:Clone()
boomSoundClone.PlayOnRemove = true
boomSoundClone.Parent = Rocket
-- Attach creator tags to the rocket early on
local creatorTag = Instance.new('ObjectValue', Rocket)
creatorTag.Value = MyPlayer
creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
local iconTag = Instance.new('StringValue', creatorTag)
iconTag.Value = Tool.TextureId
iconTag.Name = 'icon'
-- Finally, clone the rocket script and enable it
local rocketScriptClone = RocketScript:Clone()
rocketScriptClone.Parent = Rocket
rocketScriptClone.Disabled = false
end
-----------------
--| Functions |--
-----------------
local CamLoc = script.Parent:WaitForChild("CamLoc")
local function OnActivated()
local myModel = MyPlayer.Character
if Tool.Enabled and myModel and myModel:FindFirstChildOfClass("Humanoid") and myModel.Humanoid.Health > 0 then
Tool.Enabled = false
local Pos = MouseLoc:InvokeClient(MyPlayer)
local SpawnLocation = CamLoc:InvokeClient(MyPlayer)
-- Create a clone of Rocket and set its color
local rocketClone = Rocket:Clone()
DebrisService:AddItem(rocketClone, 30)
rocketClone.BrickColor = MyPlayer.TeamColor
-- Position the rocket clone and launch!
local spawnPosition = (SpawnLocation * CFrame.new(5, 0, 0)).p
rocketClone.CFrame = CFrame.new(spawnPosition, Pos) --NOTE: This must be done before assigning Parent
rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
rocketClone.Parent = workspace
--rocketClone:SetNetworkOwner(MyPlayer)
wait(RELOAD_TIME)
Tool.Enabled = true
end
end
function OnEquipped()
MyPlayer = PlayersService:GetPlayerFromCharacter(Tool.Parent)
end
--------------------
--| Script Logic |--
--------------------
Tool.Equipped:Connect(OnEquipped)
Tool.Activated:Connect(OnActivated)
--SCRIPT 2
-----------------
--| Constants |--
-----------------
local BLAST_RADIUS = 8 -- Blast radius of the explosion
local BLAST_DAMAGE = 60 -- Amount of damage done to players
local BLAST_FORCE = 1000 -- Amount of force applied to parts
local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
--NOTE: Keys must be lowercase, values must evaluate to true
-----------------
--| Variables |--
-----------------
local DebrisService = game:GetService('Debris')
local PlayersService = game:GetService('Players')
local myPlayer
local Rocket = script.Parent
local CreatorTag = Rocket:WaitForChild('creator')
local SwooshSound = Rocket:WaitForChild('Swoosh')
-----------------
--| Functions |--
-----------------
-- Removes any old creator tags and applies a new one to the target
local function ApplyTags(target)
while target:FindFirstChild('creator') do
target.creator:Destroy()
end
local creatorTagClone = CreatorTag:Clone()
DebrisService:AddItem(creatorTagClone, 1.5)
creatorTagClone.Parent = target
end
-- Returns the ancestor that contains a Humanoid, if it exists
local function FindCharacterAncestor(subject)
if subject and subject ~= workspace then
local humanoid = subject:FindFirstChildOfClass('Humanoid')
if humanoid then
return subject, humanoid
else
return FindCharacterAncestor(subject.Parent)
end
end
return nil
end
local function IsInTable(Table,Value)
for _,v in pairs(Table) do
if v == Value then
return true
end
end
return false
end
-- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
local TaggedHumanoids = {}
local function OnExplosionHit(hitPart, hitDistance, blastCenter)
if hitPart and hitDistance then
local character, humanoid = FindCharacterAncestor(hitPart.Parent)
if character then
local myPlayer = CreatorTag.Value
if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
local player = PlayersService:GetPlayerFromCharacter(character)
if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
return
end
end
end
if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
if not IsInTable(TaggedHumanoids,humanoid) then
print("Tagged")
table.insert(TaggedHumanoids,humanoid)
ApplyTags(humanoid)
humanoid:TakeDamage(BLAST_DAMAGE)
end
else -- Loose parts and dead parts are blasted
--if hitPart.Name ~= 'Handle' then
hitPart:BreakJoints()
local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
blastForce.Force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
DebrisService:AddItem(blastForce, 0.1)
--end
end
end
end
local function OnTouched(otherPart)
--if Rocket and otherPart then
-- Fly through anything in the ignore list
myPlayer = CreatorTag.Value
-- Create the explosion
local explosion = Instance.new('Explosion')
explosion.BlastPressure = 0 -- Completely safe explosion
explosion.BlastRadius = BLAST_RADIUS
explosion.ExplosionType = Enum.ExplosionType.NoCraters
explosion.Position = Rocket.Position
explosion.Parent = workspace
-- Connect custom logic for the explosion
explosion.Hit:Connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
-- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
script.Parent = explosion
CreatorTag.Parent = script
Rocket:Destroy()
--end
end
--------------------
--| Script Logic |--
--------------------
while true do
Rocket.Touched:Connect(OnTouched)
wait(0.2)
end
SwooshSound:Play()