I'm making a speed meter gui that makes certain image labels only visible when a player reaches a certain speed. My problem is when the player slows down in speed the gui doesn't update until the player presses another button. I tried using elseif statements, but I got the same result.
local dude = script.Parent local disguy = game.Players.LocalPlayer.PlayerGui.ScreenGui1:WaitForChild("SpeedCounterFrame") dude.Running:connect(function() if dude.WalkSpeed < 30 then disguy.SpeedCounter1.Visible = false end end) dude.Running:connect(function() if dude.WalkSpeed > 30 then disguy.SpeedCounter1.Visible = true end end) dude.Running:connect(function() if dude.WalkSpeed < 60 then disguy.SpeedCounter2.Visible = false end end) dude.Running:connect(function() if dude.WalkSpeed > 60 then disguy.SpeedCounter2.Visible = true end end) dude.Running:connect(function() if dude.WalkSpeed < 90 then disguy.SpeedCounter3.Visible = false end end) dude.Running:connect(function() if dude.WalkSpeed > 90 then disguy.SpeedCounter3.Visible = true end end) dude.Running:connect(function() if dude.WalkSpeed < 6000 then disguy.SpeedCounterHighest.Visible = false end end) dude.Running:connect(function() if dude.WalkSpeed > 6000 then disguy.SpeedCounterHighest.Visible = true end end)
Try this.
local dude = script.Parent local disguy = game.Players.LocalPlayer.PlayerGui.ScreenGui1:WaitForChild("SpeedCounterFrame") dude:GetPropertyChangedSignal("WalkSpeed"):connect(function() if dude.WalkSpeed <= 30 then disguy.SpeedCounter1.Visible = false end if dude.WalkSpeed >= 30 then disguy.SpeedCounter1.Visible = true end if dude.WalkSpeed <= 60 then disguy.SpeedCounter2.Visible = false end if dude.WalkSpeed >= 60 then disguy.SpeedCounter2.Visible = true end if dude.WalkSpeed <= 90 then disguy.SpeedCounter3.Visible = false end if dude.WalkSpeed >= 90 then disguy.SpeedCounter3.Visible = true end if dude.WalkSpeed <= 6000 then disguy.SpeedCounterHighest.Visible = false end if dude.WalkSpeed >= 6000 then disguy.SpeedCounterHighest.Visible = true end end)
The thing that caused you to fail is that Running
fires directly after they start/stop, and if you have some sort of speed fading script, it stacks directly with this one, and fires at the exact time that this one does (assuming that the fading script uses Humanoid.Running
, which WOULD be the most efficient way). With dude:GetPropertyChangedSignal("WalkSpeed")
, it will fire every time that dude.WalkSpeed
changes.
PS: Use the SAME function for stuff if you're gonna use the same function every time. It really helps to shorten up the code, as well as reduce lag!