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)
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
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 :)