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

Script isn't detecting WalkSpeed change?

I have a script in StarterCharacterScripts with this code

person = script.Parent
personspeed = person.Humanoid.WalkSpeed

while true do
	print(personspeed)
	wait(1)
end

It prints "20" when I run the game, but when i change the WalkSpeed of my character it will continue to print "20". Any help?

2 answers

person = script.Parent
personspeed = person.Humanoid.WalkSpeed

while true do
	print(personspeed)
	wait(1)
	script.Parent.Script:Destroy()
end

I might of fixed the problem. You forgot to put "script.Parent.Script:Destroy()" Please let me know if this does not work.

You may be better off using .Changed to call a function whenever the WalkSpeed changes. The parameter returned by .Changed is the property of the Instance that was changed. See here: https://developer.roblox.com/en-us/api-reference/event/Instance/Changed

Example:

local person = script.Parent -- also it's good practice to include "local" in your variables.
local Humanoid = person.Humanoid

Humanoid.Changed:Connect(function(WhatWasChanged)
	if WhatWasChanged == Humanoid.WalkSpeed then
		print(Humanoid.WalkSpeed.Value)
	end
end)

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