So I'm trying to make a rocket that explodes when it touches an object, but I've been noticing that the rocket seems to detonate earlier, as if it didn't touch anything. So I put a representation of where the rocket hit and I got this. https://imgur.com/FGXiu4j The rocket touches... nothing prematurely? Even though the output says it touched the wall. Here's the script

 local rs = game:GetService("ReplicatedStorage")

local makebulletevent = Instance.new("RemoteEvent")

makebulletevent.Parent = rs

makebulletevent.Name = ("MakeBulletEvent " .. script.Parent.Name)

math.randomseed(tick())

  

local function makethebullet(player, color1, color2, color3)

script.Parent.Nozzle.Pew:Play()

  

  

local lifetime = script.Parent.GunStats.BulletLife.Value

local damage = script.Parent.GunStats.Damage.Value

local bulletspeed = script.Parent.GunStats.BulletSpeed.Value

local rootpart =player.Character:FindFirstChild("HumanoidRootPart")

local rootcf =rootpart and rootpart.CFrame

local firedir =rootcf.lookVector*bulletspeed

local bonusdamage = player.Character:WaitForChild("BonusDamage").Value

  

local bullet =Instance.new("Part")

bullet.Parent = game.Workspace

local vel =Instance.new("BodyVelocity")

vel.Parent = bullet

vel.MaxForce =Vector3.new(100/0,100/0,100/0)

vel.Velocity =firedir

bullet.BrickColor = BrickColor.new(color1, color2 ,color3 )

bullet.Size =Vector3.new(1,1,2)

bullet.BottomSurface = "Smooth"

bullet.TopSurface = "Smooth"

bullet.Name =("Bullet".. " " .. player.Character.Name)

bullet.Shape ="Block"

bullet.CFrame =rootcf*CFrame.new(0,0,-3)

bullet.CanCollide =false

bullet.Transparency = 0

bullet.Anchored = false

bullet:BreakJoints()

bullet.Touched:Connect(function(hit)

if hit.Name ~= ("Bullet " .. player.Name) and hit.Name ~= ("Smoke") and hit.Name ~= ("Explodey") and hit.Parent.Name ~= player.Name and hit.Name ~= script.Parent.Name then

print(hit.Name)

local position = bullet.Position

bullet:Destroy()

local pos = Instance.new("Part", workspace)

pos.Size = Vector3.new(1,1,1)

pos.Anchored = true

pos.CanCollide = false

pos.CFrame = CFrame.new(position.X, position.Y, position.Z)

end

end)

wait(lifetime)

bullet:Destroy()

end

  

makebulletevent.OnServerEvent:Connect(makethebullet)

I can add the script that fires this script if it's needed. Also how do you do the old coding thing with this new text editor

3 comments

0

cant read the entire script

0

How do I do the old code thing with this new text editor?

0

There's usually bugs happening with collisions. Have you tried Changing the collisiongroupid to 1 then back to 0? That usually fixes it.