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

Script isn't detecting WalkSpeed change?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
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.

Ad
Log in to vote
0
Answered by
rnelee 105
4 years ago

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)

Answer this question