Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my projectile lag for a second?

https://gyazo.com/f7db9d8cf952b09ab493de8c6ba8dbf6

When the projectile is first created, you will notice a little pause. It's annoying, and I want to fix it, but I don't know what's causing it. Can someone help me make it perfectly smooth? Thanks.

wait()

VELOCITY_MIN = 100
VELOCITY_MAX = 125

SPREAD = 2
OFFSET = Vector3.new(0, 0, 0)
ANTI_GRAVITY = 0.995

-------------------------------

local tool = script.Parent

local part = Instance.new("Part")

part.Name = "Bullet"
part.Material = "Neon"
part.CanCollide = false
part.FormFactor = "Custom"
part.Size = Vector3.new(0.1,0.1,1.2)
part.TopSurface = "Smooth"
part.BottomSurface = "Smooth"
part.Transparency = 0

part.BrickColor = BrickColor.new("White")


script.Parent.ShootProjectile.OnServerEvent:connect(function(player, pos)
	script.Parent.Barrel.Muzzle.Enabled = true
	script.Parent.Barrel.Muzzle1.Enabled = true
	script.Parent.Barrel.Muzzle2.Enabled = true
	script.Parent.Barrel.Muzzle3.Enabled = true
	
	script.Parent.Barrel.PointLight.Enabled = true
	
	script.Parent.slide.Transparency = 1
	script.Parent.slide2.Transparency = 0
	
	script.Parent.pistol_fire:Play()
	
	if player.Character then
		local shoot_from = script.Parent.Barrel
		if shoot_from then
			local missile = part:clone()
			local spawnpos = (shoot_from.CFrame * CFrame.new(OFFSET)).p
			missile.CFrame = CFrame.new(spawnpos, pos) * CFrame.Angles(math.random(-SPREAD, SPREAD)/90, math.random(-SPREAD, SPREAD)/90, 0)
			missile.Velocity = missile.CFrame.lookVector * (math.random(VELOCITY_MIN, VELOCITY_MAX))

			local creator_tag = Instance.new("ObjectValue")
			creator_tag.Name = "creator"
			creator_tag.Value = player
			creator_tag.Parent = missile

			script.Traits:clone().Parent = missile

			local bforce = Instance.new("BodyForce")
			bforce.force = Vector3.new(0, missile:GetMass() * 196.2 * ANTI_GRAVITY, 0)
			bforce.Parent = missile


			local missile_script = script.ProjectileScript:clone()
			missile_script.Parent = missile

			missile.Parent = game.Workspace
			missile_script.Disabled = false
			wait(0.05)
	script.Parent.Barrel.Muzzle.Enabled = false
	script.Parent.Barrel.Muzzle1.Enabled = false
	script.Parent.Barrel.Muzzle2.Enabled = false
	script.Parent.Barrel.Muzzle3.Enabled = false
	
	script.Parent.Barrel.PointLight.Enabled = false
	script.Parent.slide.Transparency = 0
	script.Parent.slide2.Transparency = 1
		end
	end
end)

this is the code that creates the projectiles.

2 comments

0

code?

0

i updated it

1 answer

I'm sorry to tell you that this problem likely can't be fixed, it's a problem with the roblox engine. But you can use RayCasts to overcome this problem.

I would advise you to look more into RayCasting.

This discussion is preserved as it was. New answers, comments, and votes are closed.