Not able to compare player's character

I am scripting a gun using fastcast, but i have a problem. I cant compare the character i found in client side with the character i found in the server side.

I don’t really know how to explain it so i will show some samples of the code.

Local script:

local function OnRayHit(cast, result, segmentvelocity, bullet)
	bullet:Destroy()
	if result.Instance then
		local hit = result.Instance
		local char = hit:FindFirstAncestorWhichIsA("Model")
		if char then
			local humanoid = char:FindFirstChild("Humanoid")
			if humanoid then
				script.Parent.RegisterHitEvent:FireServer(char,hit)
			end
		end
	end
end)

Server Script:

script.Parent.RegisterHitEvent.OnServerEvent:Connect(function(player,character,hit)
	for i,v in pairs(game.Workspace:GetChildren()) do --Look for everything inside game.Workspace
		if v:FindFirstChildWhichIsA("Humanoid") then --Filter the models with humanoids
			if (character.PrimaryPart.Position - v.PrimaryPart.Position).Magnitude > 5 then
				if v == character then --CANT COMPARE CHARACTER WITH CHARACTER
					print(character) --DOSENT PRINT
					print(hit) --DOSENT PRINT
				end
			end
		end
	end
end)

What are the actual values of v and character when it doesn’t print?

The V value is the model with a humanoid that is found in the server, and the character is the value that is found in the client. I’m doing this because using remotes to take information from client to server takes too long and makes the raycasts inaccurate, so i take both values, and check their distances.

I just found out i had to use < (less than) operator instead of the > (greater then) operator in the distance check condition. :moyai: :moyai:

Sorry.

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