Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED BY MYSELF] For some reason this only works with really high values (around 1000+)?

I have solved this myself.

So i have some code that in theory should kick someone with a speed over 16 (maxWalkSpeed is a value from a module script), but it only kicks them with a speed around over 1000, does anyone know why this happens?

local requireed = require(script.Parent)
local maxWalkSpeed = requireed.maxWalkSpeed
game.Players.PlayerAdded:Connect:Function(plr)
plr.CharacterAdded:Connect(function(char)
local HPR = char.HumanoidRootPart
local KickText = "kicked"
while true do wait(.2)
local pos1 = HPR.Position
wait(1)
local pos2 = HPR.Position
if pos1.X - pos2.X > maxWalkSpeed * maxWalkSpeed then
		plr:Kick(KickText)
end
if pos1.Z - pos2.Z > maxWalkSpeed * maxWalkSpeed then
		plr:Kick(KickText)	
end
end)
end)

Something to note is that IT DOES somewhat work, just only with very high values, and I use maxWalkSpeed * maxWalkSpeed because before then it just kicked the player with any speed AND maxWalkSpeed is 16.

5 comments

0

You are only checking the z or x delta between the positions, you should do magnitude which checks each axis

0

So that would be if (pos1- pos2).Magnitude > maxWalkSpeed * maxWalkSpeed then

0

The reason is X -X can be negative which alread would fail ur condition, and Magnitude is the distance between two positions so it cant be negative

0

Also maxWalkSpeed^2 is quite a bit excessive to prevent false positives if you want to make sure you dont get false positives you should do maxWalkSpeed*2, or even lower if its reliable

0

WalkSpeed is after all studs per seconds

1 answer

✓ Accepted answer

I decided to make the comments i had wrote into an Answer.

What you are doing atm is checking if the delta between two axis is higher than the root of walkspeed. this could fail multiways and be very inaccurate. first of all delta axis could be negative for example 5 - 500, which should ve kicked the player but didnt next you are doing the root of maxWalkSpeed which grants the player a lots room where he can cheat but not be detected. like say maxwalkspeed is 16 which would 256 in which you compare, meaning player could go up to 256 without being detected. at max i would do 16 *2 which 32, which leaves enough room to prevent false positives.

Instead of doing delta of each axis you should be doing Magnitude of said Positions, Magnitude of the subtraction of two positions is the distance between them.

so at the end we get this

local requireed = require(script.Parent)
local maxWalkSpeed = requireed.maxWalkSpeed
local multi = 2

game.Players.PlayerAdded:Connect:Function(plr)
	plr.CharacterAdded:Connect(function(char)
	local HPR = char.HumanoidRootPart
	local KickText = "kicked"

	while true do wait(.2)
		local pos1 = HPR.Position
		wait(1)
		local pos2 = HPR.Position
		if (pos1- pos2).Magnitude > maxWalkSpeed * multi then
      		 	plr:Kick(KickText)
		end
	end)
end)

but this still can lead to false positives, for example if a player falls into the void or falls from great heights, his speed will massively increase and will pass the Magnitude check. The counter this you can leave out checking Y coordinate but this leaves the player again room to cheat in the Y direction.

3 comments

0

thanks for the extra help!

0

uhh the way you've done this just kicks the player when they join

0

never mind thanks just adding a wait solves this

This discussion is preserved as it was. New answers, comments, and votes are closed.