Bullet not spawning correctly (When moving)

So I am making a Revolver game and I am trying to add Trail Bullets. Nothing is wrong with the bullet itself but when it spawns while you are moving. When you stand still it works well but when you move it seems to have a delayed start up or something like that.

Here is a video:

Here is the code used to spawn the bullet:

local newbullet = game.ReplicatedStorage.RayTracers.RayTrace:Clone()
	newbullet.Parent = game.Workspace
	newbullet.Anchored = true
	newbullet.CanCollide = false
	newbullet.CFrame = script.Parent.Handle.CFrame
	
	local newweld = Instance.new("Weld")
	newweld.Parent = script.Parent.Handle
	newweld.Part0 = script.Parent.Handle
	newweld.Part1 = newbullet
	
	newbullet.CFrame = CFrame.new(newbullet.CFrame.p, position)
	
	
	
	local newpj = script.Projectile:Clone()		--- This is the script for the projectile itself (Starts off disabled)
	newpj.Parent = newbullet
	
	newpj.Vect.Value = position				--- This is the position where the mouse when fired
	newpj.Gamemode.Value = script.Parent.Gamemode.Value
	newpj.OwnerName.Value = playa.Name
	newpj.Owner.Value = playa.Character
	
	newweld:Destroy()
	
	newpj.Disabled = false

The Projectile code itself should be alright, The bullet itself is just a part with a Trail in it and the projectile script is just a CFrame movement.

Thank you!

Its not a delay. Its just that your character is moving that you left a part on a position. All I cant think of the best way to fix this is to remove the Bullet fast enough, or just slow down the WalkSpeed of the Player.

1 Like

Try re-defining your “position” variable right above newpj.Vect.Value

local newbullet = game.ReplicatedStorage.RayTracers.RayTrace:Clone()
	newbullet.Parent = game.Workspace
	newbullet.Anchored = true
	newbullet.CanCollide = false
	newbullet.CFrame = script.Parent.Handle.CFrame
	
	local newweld = Instance.new("Weld")
	newweld.Parent = script.Parent.Handle
	newweld.Part0 = script.Parent.Handle
	newweld.Part1 = newbullet
	
	newbullet.CFrame = CFrame.new(newbullet.CFrame.p, position)
	
	
	
	local newpj = script.Projectile:Clone()		--- This is the script for the projectile itself (Starts off disabled)
	newpj.Parent = newbullet
	--Here, re-define the variable
        position = WhateverYouPutHere
	newpj.Vect.Value = position				--- This is the position where the mouse when fired
	newpj.Gamemode.Value = script.Parent.Gamemode.Value
	newpj.OwnerName.Value = playa.Name
	newpj.Owner.Value = playa.Character
	
	newweld:Destroy()
	
	newpj.Disabled = false
1 Like

“position” is the target location for where the mouse is I want the bullet to aim at “position” the start location should be The Handle CFrame.

1 Like

Ah i thought you defined position as your CFrame math, basically your issue in that code is theres a delay as code is run from top-down (unless you use threads), So your variable is actually set to a value maybe 0.2 seconds in the past, you just wanna re-define your variable before you set the position of the ray itself

1 Like

I’m somewhat confused on how your code works however, I can give a suggestion on how you would go about fixing it.

Of course, if you aren’t make sure you’re doing your bullet effects client sided, this is important as one, performance issues and two, bullet spawning correctly. As the player shoots to fire the remote event, have the player shoot normally with raycasts/etc (how you do hit detection) and on the client, spawn the bullet and have it move after the hitdetection is finished and grab the new location (confusing but you may want to speed this area for it to “sync”).

3 Likes

I am unsure about Client side bullets, the reason I wanted to add them was because players in my game have no idea who shot them and bullets trails will give them a sense of where it came from.

1 Like

I am having this problem right now did anyone fix it?

but what if i want all players to see the bullet? it cant be in client