What do you want to achieve? I want the missile to call the touch event
What is the issue? Missile just flies through objects and doesn’t call touch event
What solutions have you tried so far? Tried changing my code, couldn’t find somethink helpful enough on forum
I am developing tank war game and I created missile shooting system, but I don’t know how to make it explode(touch the enemy tank and then explode), mainly because of touch event isn’t happening and I don’t know what I did wrong. I am newbie(like 3 days of programming, no docs, no ready examples) so my code can be bad.
Here is the code:
local mg_end = turret.Gun_57mm.MG_End
local shell = turret.Gun_57mm.LoadSystem.Shell57mm
local function fire()
print("I fired")
local shell_sp = turret.Gun_57mm.MG_End.CFrame * Vector3.new(0, 0, 3)
local shell_velocity = -4
local missile = shell:Clone()
missile.BTWeld:Remove()
missile.Position = shell_sp
missile.Parent = game.Workspace
missile.CanCollide = false
while missile.Parent ~= nil do
missile.CFrame = missile.CFrame * CFrame.new(shell_velocity, 0, 0)
wait(0.00001)
end
local function missileTouch(hit)
local am_explosion = Instance.new("Explosion")
am_explosion.BlastRadius = 8
am_explosion.BlastPressure = 500000
am_explosion.Position = missile.Position
am_explosion.Parent = game.Workspace
missile.Parent = nil
end
while wait(3) do
wait(.1)
missile.Touched:Connect(function()
print("HA I TOUCHED IT")
end)
missile.Touched:Connect(missileTouch())
end
end
uis.InputBegan:Connect(function(input, gameProcessedEvent, player)
if input.KeyCode == Enum.KeyCode.E and gun_seat:GetAttribute("isOccupied") == 1 then
fire()
end
end)
Its no problem, you never passed in the hit argument to the function
do this:
local mg_end = turret.Gun_57mm.MG_End
local shell = turret.Gun_57mm.LoadSystem.Shell57mm
local function fire()
print("I fired")
local shell_sp = turret.Gun_57mm.MG_End.CFrame * Vector3.new(0, 0, 3)
local shell_velocity = -4
local missile = shell:Clone()
missile.BTWeld:Remove()
missile.Position = shell_sp
missile.Parent = game.Workspace
missile.CanCollide = false
while missile.Parent ~= nil do
missile.CFrame = missile.CFrame * CFrame.new(shell_velocity, 0, 0)
wait(0.00001)
end
local function missileTouch(hit)
local am_explosion = Instance.new("Explosion")
am_explosion.BlastRadius = 8
am_explosion.BlastPressure = 500000
am_explosion.Position = missile.Position
am_explosion.Parent = game.Workspace
missile.Parent = nil
end
while wait(3) do
wait(.1)
missile.Touched:Connect(function(hit)
print("HA I TOUCHED IT")
end)
missile.Touched:Connect(function(hit)
missileTouch(hit)
end)
end
end
uis.InputBegan:Connect(function(input, gameProcessedEvent, player)
if input.KeyCode == Enum.KeyCode.E and gun_seat:GetAttribute("isOccupied") == 1 then
fire()
end
end)