Top down gun help

I need help to edit the fe gun kit to work for my top down game.

I changed this (Line 512 on GunClient script): Ray.new(StartPos, Direction * Length)

to this: local NewRay = Ray.new(StartPos, Vector3.new(Direction.X, 0, Direction.Z) * Length)

It ignores the Y value like I want but it also makes it inaccurate, please help.

Can you show us the full script? Or atleast the place where you made the changes with telling us what is Direction? As you provided us with almost to no information about your question.

local function CastRay(Type, StartPos, Direction, Length, Blacklist, IgnoreWater, RealTargetHumanoid)
	debug.profilebegin("CastRay_(GunClient_"..Tool.Name..")")
	local Blacklist = CloneTable(Blacklist)
	local ShouldIgnoreHumanoid = CurrentModule.IgnoreHumanoids
	if Type ~= "Beam" then
		ShouldIgnoreHumanoid = false
	end
	local Iterations = 0
	local NewRay = Ray.new(StartPos, Vector3.new(Direction.X, 0, Direction.Z) * Length)
	local HitPart, HitPoint, HitNormal, HitMaterial = nil, StartPos + (Direction * Length), Vector3.new(0, 1, 0), Enum.Material.Air
	while Iterations < 20 do
		Iterations = Iterations + 1
		HitPart, HitPoint, HitNormal, HitMaterial = Workspace:FindPartOnRayWithIgnoreList(NewRay, Blacklist, false, IgnoreWater)
		if HitPart then
			local Target = HitPart:FindFirstAncestorOfClass("Model")
			local TargetHumanoid = Target and Target:FindFirstChildOfClass("Humanoid")
			local TargetTool = HitPart:FindFirstAncestorOfClass("Tool")
			if RealTargetHumanoid and TargetHumanoid then
				ShouldIgnoreHumanoid = (RealTargetHumanoid ~= TargetHumanoid)
			end
			if (--[[not HitPart.CanCollide
				or]] HitPart.Transparency > 0.75
					or HitPart.Name == "Handle"
					or (
						TargetHumanoid and (
							TargetHumanoid.Health <= 0
							or not DamageModule.CanDamage(Target, Character, CurrentModule.FriendlyFire)
							or ShouldIgnoreHumanoid
						)
					)
					or TargetTool) then
				table.insert(Blacklist, HitPart)
			else
				break
			end				
		else
			break
		end
	end
	debug.profileend()
	return HitPart, HitPoint, HitNormal, HitMaterial
end

local function Get3DPosition(Type, CurrentPosOnScreen)
	local InputRay = Camera:ScreenPointToRay(CurrentPosOnScreen.X, CurrentPosOnScreen.Y, 1000)
	local EndPos = InputRay.Origin + InputRay.Direction
	local HitPart, HitPoint, HitNormal, HitMaterial = CastRay(Type, Camera.CFrame.p, (EndPos - Camera.CFrame.p).Unit, 1000, IgnoreList, true)
	return HitPoint
end

So is direction the players mouse? as its not specified.

Yes, I didn’t include the part where it gets the crosshairs absolute position.

local function Get3DPosition2()
	local Type = CurrentModule.LaserBeam and "Beam" or "Tip"
	if Module.DirectShootingAt == "None" then
		return Get3DPosition(Type, GUI.Crosshair.Center.AbsolutePosition)
	else
		local FirePointObject = HandleToFire:FindFirstChild("GunFirePoint"..CurrentFireMode)
		if FirePointObject ~= nil then
			local Direction = ((FirePointObject.WorldCFrame * CFrame.new(0, 0, -5000)).p - FirePointObject.WorldPosition).Unit		
			local HitPart, HitPoint, HitNormal, HitMaterial = CastRay("Direct", FirePointObject.WorldPosition, Direction, 5000, IgnoreList, true)
			if Module.DirectShootingAt == "Both" then
				return HitPoint
			else
				if Module.DirectShootingAt == "FirstPerson" then
					if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude <= 2 then
						return HitPoint
					else
						return Get3DPosition(Type, GUI.Crosshair.Center.AbsolutePosition)
					end
				elseif Module.DirectShootingAt == "ThirdPerson" then
					if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude > 2 then
						return HitPoint
					else
						return Get3DPosition(Type, GUI.Crosshair.Center.AbsolutePosition)
					end
				end
			end			
		else
			return Get3DPosition(Type, GUI.Crosshair.Center.AbsolutePosition)
		end
	end
end

Yea… Don’t do that. Use mouse.hit.Position as I am sure Crossair and mousep is almost the same?

ok… I’ve changed it to Mouse.Hit.Position as you said, yes its the same. Still inaccurate

local function CastRay(Type, StartPos, Direction, Length, Blacklist, IgnoreWater, RealTargetHumanoid)
	debug.profilebegin("CastRay_(GunClient_"..Tool.Name..")")
	local Blacklist = CloneTable(Blacklist)
	local ShouldIgnoreHumanoid = CurrentModule.IgnoreHumanoids
	if Type ~= "Beam" then
		ShouldIgnoreHumanoid = false
	end
	local Iterations = 0
	local NewRay = Ray.new(StartPos, Vector3.new(Direction.X, 0, Direction.Z) * Length)
	local HitPart, HitPoint, HitNormal, HitMaterial = nil, StartPos + (Direction * Length), Vector3.new(0, 1, 0), Enum.Material.Air
	while Iterations < 20 do
		Iterations = Iterations + 1
		HitPart, HitPoint, HitNormal, HitMaterial = Workspace:FindPartOnRayWithIgnoreList(NewRay, Blacklist, false, IgnoreWater)
		if HitPart then
			local Target = HitPart:FindFirstAncestorOfClass("Model")
			local TargetHumanoid = Target and Target:FindFirstChildOfClass("Humanoid")
			local TargetTool = HitPart:FindFirstAncestorOfClass("Tool")
			if RealTargetHumanoid and TargetHumanoid then
				ShouldIgnoreHumanoid = (RealTargetHumanoid ~= TargetHumanoid)
			end
			if (--[[not HitPart.CanCollide
				or]] HitPart.Transparency > 0.75
					or HitPart.Name == "Handle"
					or (
						TargetHumanoid and (
							TargetHumanoid.Health <= 0
							or not DamageModule.CanDamage(Target, Character, CurrentModule.FriendlyFire)
							or ShouldIgnoreHumanoid
						)
					)
					or TargetTool) then
				table.insert(Blacklist, HitPart)
			else
				break
			end				
		else
			break
		end
	end
	debug.profileend()
	return HitPart, HitPoint, HitNormal, HitMaterial
end

local function Get3DPosition(Type)
	local EndPos = Mouse.Hit.Position
	local HitPart, HitPoint, HitNormal, HitMaterial = CastRay(Type, Camera.CFrame.p, (EndPos - Camera.CFrame.p).Unit, 1000, IgnoreList, true)
	return HitPoint
end

local function Get3DPosition2()
	local Type = CurrentModule.LaserBeam and "Beam" or "Tip"
	if Module.DirectShootingAt == "None" then
		return Get3DPosition(Type)
	else
		local FirePointObject = HandleToFire:FindFirstChild("GunFirePoint"..CurrentFireMode)
		if FirePointObject ~= nil then
			local Direction = ((FirePointObject.WorldCFrame * CFrame.new(0, 0, -5000)).p - FirePointObject.WorldPosition).Unit		
			local HitPart, HitPoint, HitNormal, HitMaterial = CastRay("Direct", FirePointObject.WorldPosition, Direction, 5000, IgnoreList, true)
			if Module.DirectShootingAt == "Both" then
				return HitPoint
			else
				if Module.DirectShootingAt == "FirstPerson" then
					if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude <= 2 then
						return HitPoint
					else
						return Get3DPosition(Type)
					end
				elseif Module.DirectShootingAt == "ThirdPerson" then
					if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude > 2 then
						return HitPoint
					else
						return Get3DPosition(Type)
					end
				end
			end			
		else
			return Get3DPosition(Type)
		end
	end
end

Hmm, thats odd. Well I suppose what you can do is instead of using Direction like that you can do:

local dir = Mouse.Hit.Position-StartPos
local Ray = Ray.new(StartPos,Vector3.new(math.clamp(dir.X,-length,length),0,math.clamp(dir.Z,-length,length))

?

Vector3.new(Direction.X, 0, Direction.Z).Unit rather than Vector3.new(Direction.X, 0, Direction.Z)

doesnt work :pensive:

////////////////////

ok… ive got this, its accurate, doesnt shoot up but it shoots down

local function Get3DPosition(Type)
	local EndPos = Vector3.new(Mouse.Hit.Position.X, 0, Mouse.Hit.Position.Z)
	print(EndPos)
	local HitPart, HitPoint, HitNormal, HitMaterial = CastRay(Type, Camera.CFrame.p, (EndPos - Camera.CFrame.p).Unit, 1000, IgnoreList, true)
	return HitPoint
end

Okay so, first of all I advise you not to use mouse.Hit.Position as it was superseded.
I’m not sure what exactly your problem is but I assumed it was that the bullet didn’t exactly fly where the crosshair was.
And that is not the problem from the gunClient but from the way you rotate your character dependent on your mouses Position.
You shouldn’t change the CFrame of HumanoidRootPart there but actually change the guns position so it is directed at the crosshairs position.
Another way would be to change the way the character is holding the gun.

Edit: In the video you can see that the gun is on the right of the character and pointed straight forward. Make the arms hold the gun differently.

can you share eveything related to the tool? like projectiles in replicatedstorage or modules and guns local scripts etc. maybe you can directly send us the place of it as a .rbxl file?