Issue with getting distance between a player and an object

Trying to make sure the user it not further than a set distance for a proxy prompt to prevent far grab type of exploits and it seems to not be working.

Debug Output:

 20:18:20.466  96.91646575927734  -  Server - Bagpickup:5
  20:18:20.467  [!] Potential Cheater. Far Grab type cheat detected. Kicking: thatguybarny1324 | 180983817  -  Server - Bagpickup:8

Structure of object and its children:
Ignore the part instance just chilling there. It hovers above the bag a little to make accessing the prompt easier.
image

Server Script Code:

(LOCAL SCRIPT IS NOT IMPORTANT JUST DOES A NOTIFICATION TO THE CLIENT WHO PICKED UP THE BAG. DOES NOT DO ANY KIND OF IMPORTANT HANDLING.)
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	
	-- Focus here
	
	local dist: number = player.Character:FindFirstChild("Torso").CFrame.Position.Magnitude
	
	print(dist)
	
	if dist > 10 then
		print("[!] Potential Cheater. Far Grab type cheat detected. Kicking: "..player.Name.." | "..player.UserId)
		player:Kick("Far Grab type cheat detected. Kicking: "..player.Name.." | "..player.UserId.."\nIf you believe this to be an mistake please open a ticket in our support discord.")
	end
	
	-- Focus above. Ignore below.
	
	--========================================================
	
	-- main stuff after checks
	
	local UUID: string = script.Parent:GetAttribute("UUID")
	
	if UUID == nil then
		
		player:Kick("U32 | Disconnected.")
	
	end
	
	local char = player.Character
	local bags = char:FindFirstChild("Bag")
	
	local bagPart = Instance.new("Part", bags) -- used to store bag data on the player
	local bagPartVal = Instance.new("IntValue", bagPart) -- used to store the value on the player
	
	if bagPart.Parent ~= bags then
		bagPart.Parent = bags
	elseif bagPartVal.Parent ~= bagPart then
		bagPartVal.Parent = bagPart
	end
	
	bagPartVal.Value = script.Parent.Amount.Value
	
	bagPart.CanCollide = false
	bagPart.Anchored = true
	bagPart.Transparency = 1
	
	bagPart.Name = UUID
	
end)

Knowing some people will go below and look at the rest of the code.

  1. Why is there a UUID Check? A: Exploiters can clone the bag from replicated storage. The reason why is to catch exploiters off guard and easily ban them.
  2. Why is the cash an IntValue instance and not an attribute? I was not bothered by making both attributes and also makes some exploiters looking through dirs to see that and try to pick the bag up.

I’m assuming you want to compare the distance between the player and the part (script.Parent). I noticed you checked the player’s torso position magnitude but you didn’t subtract it from the part’s position. Does this variable work?

local dist: number = (player.Character:FindFirstChild("Torso").CFrame.Position-script.Parent.Position).Magnitude
1 Like

I will try this. I havent done checking with magnitude in a little bit so I might have forgotten to do some things. I will mark this as the solution if this is correct!

It’s because you’re not actually comparing the position with the part

local dist: number = (player.Character:FindFirstChild("Torso").CFrame.Position - partPath.Position).Magnitude

You can also use Math.Floor() to remove decimals.

1 Like

Right got you. Also it worked! 20:29:25.674 1.6728523969650269 - Server - Bagpickup:7

I keep forgetting to actually subtract both of the instances to get the true distance between but instead think that it will by its self return the true distance. I will also use math.Floor() to simplify the output too thanks!

1 Like

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