False ping hit triggers in game

ignore anything commented out most of it is by my friend who made the script

modular script that handles anything gun related

function Shoot(Player, target, otherChar)
	
	warn("Shoot Request[RECIEVED]: " .. Player.Name.. " --> " .. otherChar.Name)
	
	if Player.Character == nil then
		return
	end
	local character = Player.Character
	if character:FindFirstChild("Humanoid") == nil then
		return
	end
	if character.Humanoid.Health == 0 then
		return
	end
	if GunFunctions.TryGetCharacterGun(character) == nil then
		return
	end
	
	--TEST IG COULD WORK BUT IDK
	if character:GetAttribute("GunTimer") <= 0 then
		return
	end

	local player = Players:GetPlayerFromCharacter(character)
	local Gun = GunFunctions.TryGetCharacterGun(character)
	
	
	if character:GetAttribute("GunEquipped") == true and character:GetAttribute("CanShoot") == true then
		
		if character:GetAttribute("Reloading") == false then
			



			--TRACER (this will be long)
			local ShowTracer = false


			local Muzzle = Gun:FindFirstChild("Muzzle")
			local TracerBeam = Muzzle:FindFirstChild("Beam")
			local TracerAtt0 = Muzzle:FindFirstChild("Att0")
			local TracerAtt1 = Muzzle:FindFirstChild("Att1")
			local MuzzleFlashP = Muzzle:FindFirstChild("MuzzleFlashParticle")
			local MuzzleFlashL = Muzzle:FindFirstChild("MuzzleFlashLight")

			if TracerAtt0 == nil or TracerAtt1 == nil or TracerBeam == nil --[[or target == nil]] then
				return
			end
			if TracerAtt0:IsA("Attachment") and TracerAtt1:IsA("Attachment") and TracerBeam:IsA("Beam") --[[ and typeof(target) == "Vector3"]] then

				local GunShotSound = Gun.GunSounds.GunShotSound
				
				AnimTracks.PlayPlayerAnim(player.Name, "ShootAnim")
				
				
				GunShotSound:Play()
				

				--[[
				local clonedAtt0 = TracerAtt0:Clone()
				clonedAtt0.Parent = TracerAtt0.Parent	
				local clonedAtt1 = TracerAtt1:Clone()
				clonedAtt1.Parent = TracerAtt1.Parent
				local clonedBeam = TracerBeam:Clone()
				clonedBeam.Parent = TracerBeam.Parent
				]]

					
				local clonedMFP = MuzzleFlashP:Clone()
				clonedMFP.Parent = MuzzleFlashP.Parent
				local clonedMFL = MuzzleFlashL:Clone()
				clonedMFL.Parent = MuzzleFlashL.Parent



				--[[
				clonedAtt1.WorldPosition = target
				clonedBeam.Attachment1 = clonedAtt1
				clonedBeam.Attachment0 = clonedAtt0
				]]


					--hacky fix but does for now
				local BeamPart = Instance.new("Part", workspace)
				BeamPart.Anchored = true
				BeamPart.Transparency = 1
				BeamPart.CanCollide = false
				BeamPart.CanQuery = false
				BeamPart.CanTouch = false
				BeamPart.CFrame = TracerAtt0.WorldCFrame


				--[[
				clonedAtt0.Parent = BeamPart
				clonedAtt1.Parent = BeamPart
				clonedBeam.Parent = BeamPart
				]]





				clonedMFP.Enabled = true
				clonedMFL.Enabled = true


				--[[
				Debris:AddItem(clonedBeam, 0.2)
				Debris:AddItem(clonedAtt0, 0.2)
				Debris:AddItem(clonedAtt1, 0.2)

				Debris:AddItem(BeamPart, 0.2)
				]]	
					

				Debris:AddItem(clonedMFP, 0.15)
				Debris:AddItem(clonedMFL, 0.15)



			end

			if otherChar == nil then
				return
			end
			
			local returnResult = false
			

				--local otherChar = rayresult.Instance:FindFirstAncestorOfClass("Model")
				local otherPlayer = Players:GetPlayerFromCharacter(otherChar)
				local Hum = otherChar:FindFirstChild("Humanoid")
				

				if Hum and Hum.Health ~= 0 and otherChar:GetAttribute("GunName") ~= nil--[[ and otherChar:GetAttribute("Ragdolled") ~= true]] then

					
					
					AnimTracks.StopPlayerAnim(player.Name, "ShootAnim")
					
					
					GunFunctions.UnequipGun(Player.Character)
					
					local GunTimer = character:GetAttribute("GunTimer")
					if GunTimer <= 0 then
						character.Humanoid.Health = 0
						return
					end
					
					--[[
					GunFunctions.EquipGun(otherChar)
					
					BE_SetRoundStatus:Fire(otherPlayer.Name .. " has the Gun!")
					]]
					
					
					
					task.spawn(function()
						
						warn("Shoot Request[CONFIRMED]: " .. Player.Name.. " --> " .. otherChar.Name)
						
						--tako insert
						if Player.Character:FindFirstChild("Humanoid") then
							Player.Character.Humanoid.WalkSpeed = 28

						end
						
						otherPlayer:SetAttribute("LastShotBy", Player.Name)
						
						BE_Ragdoll:Fire(otherChar)
						
						local humanoidRootPart = otherChar:FindFirstChild("HumanoidRootPart")
						
						local ForceAtt0 = Instance.new("Attachment", humanoidRootPart)
						local VectorForce = Instance.new("VectorForce", humanoidRootPart)
						
						
						local hitDirection = (humanoidRootPart.Position - Player.Character.HumanoidRootPart.Position).unit
						hitDirection *= Vector3.new(2900, 100, 2900)
						
						--warn(hitDirection)
						--[[
						-- Calculate the direction vector from the attachment to the target part
						local direction = (Player.Character.Torso.Position - ForceAtt0.WorldPosition).Unit

						-- Calculate the CFrame that points the attachment towards the target
						local lookAtCFrame = CFrame.lookAt(ForceAtt0.WorldPosition, Player.Character.Torso.Position)

						-- Apply the 180-degree rotation to the lookAtCFrame
						local rotatedCFrame = lookAtCFrame * CFrame.Angles(0, math.rad(180), 0)

						-- Apply the rotated CFrame to the attachment
						ForceAtt0.CFrame = rotatedCFrame
						
						]]
						
						
						--ForceAtt0.CFrame = ForceAtt0.CFrame * CFrame.Angles(0, math.rad(180), 0) 
						
						
						
						
						--[[
						
						if Hum.FloorMaterial == Enum.Material.Air then
							VectorForce.Force = Vector3.new(0, 0, 2000)
						else
							VectorForce.Force = Vector3.new(0, 0, 5000)
						end
						]]
						
						VectorForce.Force = hitDirection
						
						
						VectorForce.Attachment0 = ForceAtt0
						VectorForce.ApplyAtCenterOfMass = true
						
						
						
						
						
						task.wait(0.1)
						
						VectorForce:Destroy()
						ForceAtt0:Destroy()
						
						
						task.wait(1.6)
						
						if Player.Character:FindFirstChild("Humanoid") then
							Player.Character.Humanoid.WalkSpeed = 20

						end
						
						BE_UnRagdoll:Fire(otherChar)
						
						task.wait(0.2)
						
						GunFunctions.SetPlayerWithGun(otherPlayer)
					end)
					
					--Has to be spawned cuz it delays by 1 second idk WHYYYY (FIGURE OUT LATER IF IT HAS A PREF HIT)
					
					
					local GunHitSound = Gun.GunSounds.GunHitSound
					
					GunHitSound:Play()
					
					returnResult = true
					
				end
			
			Gun:SetAttribute("Magazine", Gun:GetAttribute("Magazine") - 1)
			
			GunFunctions.StartReloadTimer(character)
			return returnResult
		else
			
		end
		
	else

	end
	
end


RF_ShootRequest.OnServerInvoke = Shoot

local side

function Input(input)
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Player:GetAttribute("AssetsLoaded") then
		
		--centerTestPart.CFrame = CFrame.new(ViewportPointToWorldCoordinates())
		local Humanoid = Character:FindFirstChild("Humanoid")
		
		if Humanoid == nil then
			return
		end
		
		if Character:GetAttribute("CanShoot") == true and Character:GetAttribute("Reloading") == false and Character:GetAttribute("GunTimer") > 0 and Humanoid.Health > 0 then
			
			local  target = ViewportPointToWorldCoordinates()
			
			if DebugSwitch then
				local debugPart = Instance.new("Part", game.Workspace)
				debugPart.Name = "DebugShootPart"
				debugPart.Anchored = true
				debugPart.CanCollide = false
				debugPart.CanTouch = false
				debugPart.CanQuery = false
				debugPart.Transparency = 0.5
				debugPart.Shape = Enum.PartType.Ball
				debugPart.BrickColor = BrickColor.new(Color3.fromRGB(255, 176, 0))
				debugPart.Position = target
				
				Debris:AddItem(debugPart, 10)
			end
			
			local rayParams = RaycastParams.new()
			rayParams.FilterType = Enum.RaycastFilterType.Exclude
			rayParams.FilterDescendantsInstances = {Player:GetDescendants(), Character:GetDescendants()}

			local rayCast = Ray.new()

			local originPoint = Character:FindFirstChild("Head").Position
			local rayDestinationPoint = target
			local rayDirectionWay = (rayDestinationPoint - originPoint).Unit

			local rayresult = workspace:Raycast(originPoint, rayDirectionWay * 300, rayParams)
			local intersection = rayresult and rayresult.Position or originPoint + rayDirectionWay * 300
			local distance = (originPoint - intersection).Magnitude
			
			if rayresult.Instance:FindFirstAncestorOfClass("Model") ~= nil then
				
				local otherChar = rayresult.Instance:FindFirstAncestorOfClass("Model")
				
				--warn(otherChar.Name)
				
				task.spawn(Recoil)
				
				
				local Hum = otherChar:FindFirstChild("Humanoid")


				if Hum and Hum.Health ~= 0 and otherChar:GetAttribute("GunName") ~= nil then
					
					task.spawn(function()
						
						if HitLabel.Visible == false then
							
							HitLabel.Visible = true

							HitPlayerLabel.Visible = true
							
						end
						
						Hitmarker.Visible = true

						HitPlayerLabel.Text = otherChar.Name
						
						

						task.wait(0.3)

						Hitmarker.Visible = false
						
						task.wait(0.2)
						
						if HitLabel.Visible == true then
							
							HitLabel.Visible = false

							HitPlayerLabel.Visible = false
							
						end
						
						
					end)
					
				end
				
				
				RF_ShootRequest:InvokeServer(target, otherChar)
				
				
			end
			
			--[[
			task.spawn(Recoil)
			
			if target then
					
				local result = RF_ShootRequest:InvokeServer(target)	
				
				if result == true then
					--DO STUFF HERE ON CLIENT IF HIT
					
					
				end
			end
			
			]]
		else

		end
		
	end
	
	
	if input.KeyCode == Enum.KeyCode.F3 then
		if DebugSwitch == true then
			DebugSwitch = false
			
			NotifModule.UINotify("disabled hit visualisation", 24)
			
		else
			DebugSwitch = true
			
			NotifModule.UINotify("enabled hit visualisation", 24)
		end
	end
	
end

UIS.InputBegan:Connect(Input)

Um, may I ask why you are using a remote function? The whole point of them is to return values sent from the client to the server and vice versa. You could jsut use remote events.

From Valldoe the guy who made the script: before we use to return and it was very delayed so we remade it do you believe that causes the issue?

i believe it shouldn’t cause any issues since it returns nothing

Yeah it doesn’t return anything but it’s just sort of weird I was thinking.

we will change it but my friend believes thats not the issue
besides we dont have anyone to test the theory rn

Well I don’t think returning should be a problem, but this may be. Using deprecated things like rays. Possibly, unlikely but possible. Also I see in your code you are using alot of things that are heavy on resources like task.spawn, that might also be a cause.

since when are rays deprecated ??? also what can we use instead of rays ?

You can use raycasts instead of using rays, which you are already doing.

1 Like

sure we will try changing that! but probs isnt the problem hes currently looking if he has made any mistakes in the order of the events.

By the way I think your code for the input function may have a bug, there’s a second parameter in the event called “gameprocess” which just checks if the user clicks the input through the chat instead. Your function doesn’t check for that, meaning if a player just decides to click mousebutton1 on the chat bar it’ll count as the input and fire the raycast.

Here’s a random topic I found about this for more information about the gameprocess:

Thanks, we’re changing that right now. If you find anything else out the ordinary, let me know. For now we will do all the changes and come back to you in a few hours, since its 2am.

Does the shoot request print on the server? Also if I’m not mistaken- are you also trusting the client to correctly send in the player who got hit? I would recommend running some sort of sanity check to verify the data sent through the RemoteFunction.

Yes, we’re currently trusting the client at 100% for hit register.
What do you mean by “shoot request print on the server”?

Sorry- I meant the warn statement on the serverside function. Does that print when the laggy player hits someone (and it doesn’t register)?

Alright. This is unrelated to the current topic, but I would advise you to look into some alternatives as any exploiter could just fire the RemoteEvent as soon as they recieve the gun.

  1. We know it is very unsafe . We will work on the issue in the future, but we have bigger problems at hand right now.
  2. No, it says they haven’t hit.

Could you add a print statement next to the :InvokeServer on the client? If that one doesn’t print the the issue is likely on the clientside.

We know the issue is client sided. We cant test right now, because the bug requires a high ping player to be replicated. I will update you on the situation when we are able to test. For now we are going to fix the issues pointed out by the other developers.

Theres an option in studio where you can increase the Incoming Replication Lag, this simulates high ping

Can you give me an article!
Really thankful!

1 Like