Verifying client projectile hits based on the majority of players in a server

What I’m trying to do as a security method to prevent exploiters from abusing the fact that the projectiles I’m firing are client sided (hit detection) is to check how many clients are approving the hit is a legitimate one on their client since the projectile has fired on all clients simutaneously. I’m having trouble with making this work out.

Client: basically when the client’s projectile hits a humanoid it sends an event which is the server code below

Serve code:

			elseif Word == "ProjectileHitHumanoid" then
				local ReportingPlayer = Player
				local CasterPlayer = A
				local VictimCharacter = B	
				local Cases = script.Cases
				if ReportingPlayer == CasterPlayer then
					local ExistingCase = Cases:FindFirstChild(CasterPlayer.Name.."Hit"..VictimCharacter.Name)
					if ExistingCase ~= nil then
						ExistingCase:Destroy()
						local NewCase = Instance.new("NumberValue")
						NewCase.Name = CasterPlayer.Name.."Hit"..VictimCharacter.Name
						NewCase.Parent = Cases
						local Mark = Instance.new("Folder")
						Mark.Name = ReportingPlayer.Name
						Mark.Parent = NewCase
						NewCase.Value = NewCase.Value + 1								
					else
						local NewCase = Instance.new("NumberValue")
						NewCase.Name = CasterPlayer.Name.."Hit"..VictimCharacter.Name
						NewCase.Parent = Cases	
						local Mark = Instance.new("Folder")
						Mark.Name = ReportingPlayer.Name
						Mark.Parent = NewCase
						NewCase.Value = NewCase.Value + 1														
					end
				else
					local ExistingCase = Cases:WaitForChild(CasterPlayer.Name.."Hit"..VictimCharacter.Name)
					if not ExistingCase:FindFirstChild(ReportingPlayer.Name) then
						local Mark = Instance.new("Folder")
						Mark.Name = ReportingPlayer.Name
						Mark.Parent = ExistingCase
						ExistingCase.Value = ExistingCase.Value + 1							
					end			
				end
				local ExistingCase = Cases:FindFirstChild(CasterPlayer.Name.."Hit"..VictimCharacter.Name)
				if ExistingCase ~= nil then
					local Reporters = ExistingCase:GetChildren()
					print(#Reporters)
					for i, v in pairs(Reporters) do
						print(v.Name)
					end
					print(#_G.Players:GetPlayers())
					if #Reporters >= #_G.Players:GetPlayers() * 0.5 then
						if VictimCharacter.Humanoid.Health >= 0 then
							VictimCharacter:BreakJoints()
						end
					end 
				end
			end

Your starting the code with elseif?

Obviously not, it’s just a bit of the code lol, that’s the part which is supposed to act as a sanity check

Oh, I was going to say, hah. Hmm I’m not sure, good luck with what your making though.

I have managed to fix the issue!

How bout u describe how you fixed the problem? This would help players with a similar problem.

1 Like

Sure, here is the fixed version of the code: Casestring is a random generated number which is a string, that’s how I indentify each case

	if Word == "ProjectileHitHumanoid" then
		local ReportingPlayer = Player
		local CasterPlayer = A
		local VictimCharacter = B	
		local SpellName = C
		local CaseString = D
		local Cases = script.Cases
		local ExistingCase = Cases:FindFirstChild(CasterPlayer.Name.."Hit"..VictimCharacter.Name..CaseString)
		if ExistingCase ~= nil then
			if not ExistingCase:FindFirstChild(ReportingPlayer.Name) then
				local Mark = Instance.new("Folder")
				Mark.Name = ReportingPlayer.Name
				Mark.Parent = ExistingCase
				ExistingCase.Value = ExistingCase.Value + 1								
			end	
		else
			local NewCase = Instance.new("NumberValue")
			NewCase.Name = CasterPlayer.Name.."Hit"..VictimCharacter.Name..CaseString
			NewCase.Parent = Cases	
			_G.Debris:AddItem(NewCase, 5)
			local Mark = Instance.new("Folder")
			Mark.Name = ReportingPlayer.Name
			Mark.Parent = NewCase
			NewCase.Value = NewCase.Value + 1														
		end
		local ExistingCase = Cases:FindFirstChild(CasterPlayer.Name.."Hit"..VictimCharacter.Name..CaseString)
		if ExistingCase ~= nil then
			if #ExistingCase:GetChildren() >= #_G.Players:GetPlayers() * 0.5 then
				if VictimCharacter.Humanoid.Health >= 0 then
					VictimCharacter:BreakJoints()
				end
			end 
		end
2 Likes