Better Bullets, Advice needed

I have been making guns for a game I’m making, but I’m having problems with making the bullet collision with where it’s going work better. Here is a video of what I got
robloxapp-20211229-1557379.wmv (1.9 MB)

Don’t mind the lack of animations, I’m not done with that
But, as you can see the hitting of the bullet really isn’t that good, because the bullet just stop before or after it hits the player. Is there a better way for me to tell if the bullet is colliding with something?
here’s my current script for the bullet

	local CanHit = true
		
		local Instance_Create = BulletModel:Clone()
		CollectionService:AddTag(Instance_Create,"Bullet")

		Instance_Create.Parent = parent
		Instance_Create.Position = Pos
		
		Instance_Create.CFrame = CFrame.lookAt(Pos,Dist) * Accuracy

		Instance_Create.Anchored = false
		TweenService:Create(Instance_Create, TweenInfo.new(0.25,Enum.EasingStyle.Linear,Enum.EasingDirection.In), {Velocity = Instance_Create.CFrame.lookVector * Speed}):Play()
		Debris:AddItem(Instance_Create,6)
		
		RepEvents:FindFirstChild("BulletReturn"):FireClient(plr, Instance_Create)
		
		Instance_Create.Touched:Connect(function(hit)
			if CanHit == true then
				if hit and hit.Parent and hit.Parent ~= plr.Character and hit.Parent:FindFirstChild("Humanoid") then
					local humanoid = hit.Parent:FindFirstChild("Humanoid")
					humanoid:TakeDamage(dmg)
					Instance_Create.Anchored = true
				end
			end
		end)

This is a server-side script btw.
So is there any better way to get more accurate bullets?

why dont u just destroy the bullet after it hits a character

Ya, that’s what I’m going to do, I just want you to visuals what’s happening. Which is the collision of the bullet could be better

i dont understand what u mean just replace this with :Destroy()

I’m not actually using the line .Anchored = true. I am destroying the bullet after it’s touched. that line is just an example, my main question is, is there a better way to do bullets in roblox. then the way i am doing it

oh idk im not used to make guns but in my opinion ur code is great

1 Like

Okay, thanks for the help! III

Debris
The Debris Service is the best way to go to avoid any sort of issues with :Destroy() and remove clunkiness with any sort of other system with manually destroying an object

1 Like

Thanks for reminding me, I was going to do this. But some how forgot about it

If your bullets are small and move fast I would urge you to use raycasting
If your bullets are big and slow, what you have should be just fine

Touch detection breaks at high speeds. :frowning:

But how would I raycast it I don’t want it to just go so fast that you don’t see it
And i want the ray to follow the bullet but not hit something it’s not yet at

you can use run service to move the ray with the bullet. Also running bullets on server generally is not a good idea. I would recommend replicating the bullets to all clients through a remote event.

Maybe something like this for the ray cast.

local RayTestParams = RaycastParams.new()
RayTestParams.FilterType = Enum.RaycastFilterType.Blacklist
RayTestParams.FilterDescendantsInstances = {player.Character}

RunService.Heartbeat:Connect(function(dt)
	game:GetService("RunService").Heartbeat:Connect(function(dt)
		local rayResult = workspace:Raycast(bullet.Position, bulletMoveDirection, RayTestParams)

		if rayResult then
			print("bruuuhhh")
		end
	end)

end)
1 Like

There is a module specifically made for this purpose in #resources:community-resources
Here is a link:

Just found it last night lol so you’re in luck :smiley:

1 Like