Gun System Bullet Bug

I’m having an issue in my gun system in which the bullets aren’t taking into account the orientation of the fire point. It’s kind of hard to explain.

robloxapp-20241221-1941300.wmv (395.6 KB)

Related Code:

Tool.Activated:Connect(function()
	if not Reloading and not FireCooldown and not EquipTime then
		EventFolder.FireEvent:FireClient(Player)

		local rayParams = RaycastParams.new()
		rayParams.FilterDescendantsInstances = {Tool, Player.Character}
		rayParams.FilterType = Enum.RaycastFilterType.Blacklist
		rayParams.IgnoreWater = true

		local firePointWorldPosition = FirePoint.WorldPosition
		local firePointCFrame = FirePoint.CFrame


		local fireDirection = firePointCFrame.LookVector

		local rayResult = workspace:Raycast(firePointWorldPosition, fireDirection * SettingsModule.BulletMaxRange, rayParams)

		local hitPosition
		if rayResult then
			hitPosition = rayResult.Position

			local hitEffect = VFXFolder.ImpactEffect:Clone()
			hitEffect.Position = hitPosition
			hitEffect.Parent = workspace.GameFolder.ActiveEffects
			DebrisService:AddItem(hitEffect, 1)

		else
			hitPosition = firePointWorldPosition + fireDirection * SettingsModule.BulletMaxRange
		end

		CreateGunVFX(hitPosition)
	end
end)

Any help is appreciated

In this line.

local firePointWorldPosition = FirePoint.WorldPosition
local firePointCFrame = FirePoint.CFrame

Are those specific or same instances?
And also you should use mouse.Hit instead.

You require little code that made client script fires to the server script in order to get mouse instance.

Sorry, What do you mean by this?

My game is a sidescroller. I have to make it so the bullet goes where the gun is pointing, not where the cursor is.

I mean like, I’m assuming FirePoint is Attachment. So you should make a specific instance like you have to create a fire muzzle part.

And yes you’re trying to create shooting function like Phantom Forces. They don’t use mouse as their final hit position. Like I said, create a fire muzzle part for the fire point direction.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.