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

Humanoid Walkspeed checker not working?

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

✓ Accepted answer

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

4 comments

0

For some reason it did not work. Where did you put the local script by the way?

0

StarterGui or StarterPlayer... Maybe your walkspeed is 16

0

I had it in workspace for whatever reason, Thanks alot!

0

Welcome!

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

1 comment

0

Unfortunately this only added more errors than my original code, but this definitely will help me in the future, Appreciate it!

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