Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid Walkspeed checker not working?

Asked by 3 years ago

I'm trying to make a script to detect Walkspeed changes from the player's Humanoid, i've tried alot of ways of making this work but nothing worked, I'm an amateur lua coder; i started a month ago and im still learning the basics, dont be too harsh on me if its very blatant.

Anyways heres the code (i put the script in serverscriptservice.)

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
               local humanoid = char:WaitForChild("Humanoid")

        if humanoid.WalkSpeed == 16 then
            print("normal speed")


while true do
                    wait(0.1)

                    if (humanoid.WalkSpeed ~= 16) then 
                        print("modified")
            plr:Kick("Kicked")


            end
        end

    end
end)
end)

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I've came across this problem before and the only solution that I found is to use a LocalScript instead of a Server Script / Script

I don't know why it works for a LocalScript only but it works. There may be alternatives to this, but this worked for me

So here's the code

--LocalScript

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

while true do
    if character:WaitForChild("Humanoid").WalkSpeed ~= 16 then
        print("modified")
        player:Kick("Kicked")
    end 

    wait(1)
end

0
For some reason it did not work. Where did you put the local script by the way? x_Marwan 6 — 3y
0
StarterGui or StarterPlayer... Maybe your walkspeed is 16 TheBigBro122 427 — 3y
0
I had it in workspace for whatever reason, Thanks alot! x_Marwan 6 — 3y
0
Welcome! TheBigBro122 427 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

There is a function called :GetPropertyChangedSignal which is used to detect changes to a certain property of an object.

This is how to use it:

game.Players.PlayedAdded:Connect(function(player)
    local character = player.Character
    local humanoid = Character:WaitForChild("Humanoid") -- Humanoid contains the walkspeed property

    humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
        if humanoid.WalkSpeed == 16 then
            player:Kick("Kicked")
        end
    end)
end)

I hope this helps :)

0
Unfortunately this only added more errors than my original code, but this definitely will help me in the future, Appreciate it! x_Marwan 6 — 3y

Answer this question