1
votes

I am making a game that has different walkspeeds in different sections, but I don't want people to change their own walkspeed with hacks. My solution was to make a part and stretch it to fit the entire area and make it invisible + CanCollide disabled, and then use the child script to kill you if your walkspeed isn't what it should be:

script.Parent.Touched:connect(function(WSChecker)
    if not WSChecker.Parent then return end

    local humanoid = WSChecker.Parent:FindFirstChild("Humanoid")
    if not humanoid then return end

    if (humanoid.WalkSpeed ~= 25) then
        humanoid.Health = 0
    end
end)

Problem is that it does not work with multiple players in the part at one time, and I want to make it so it will kick the player instead of killing them. Is there a way to go about these problems? It has to check their ws only within the part, and I don't know how to make it kick whoever changed their ws instead of killing them.

5

5 Answers

1
votes

I would suggest hooking up your function to each player's Humanoid instead, and use the Humanoid.Running event.

Humanoid.Running provides you the speed they're currently running at, which means you can check if that speed is ever above a certain threshold, and punish them if it is.

Code example:

player.Character.Humanoid.Running:Connect(function(Speed)
  print(Player, "is running at speed", Speed)
end)

As for kicking, you want to use player:Kick().

0
votes
if (humanoid.WalkSpeed ~= 25) then
    game.Players.LocalPlayer:Kick()
end

that should do the trick...

0
votes

I think I can help. The solution that worked for me is:

local player = game.Players.LocalPlayer --Make sure it's a local script.
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local hum2 = char.Humanoid
script.Parent = game.StarterPlayer.StarterPlayerScripts
if hum.WalkSpeed >16 then
   player:Kick('You have been kicked for possible speed hacks.')
end
if hum2.WalkSpeed >16 then
   player:Kick('You have been kicked for possible speed hacks.')
end
0
votes
if (humanoid.WalkSpeed ~= 25) then
    game.localplayer.remove:fire
end

end)

Hopefully, this is a better solution.

0
votes

You can ofcourse do the above but as an addition to what everyone above said, checking if the walkspeed value is at the desired value is easily bypassable. Exploiters will get the raw metatable of the game and hook __index to return a normal value for WalkSpeed. Metatables cant be detected either as most modern exploits use C closures instead of Lua. Your best chance is to see how fast the character is moving and teleport them back if player is moving too fast (like a passive anticheat).