Repeat loop won't stop running after a player has stopped moving

I am currently creating a mood system for my game, but I have ran into a probloem that I can’t seem to figure out, when the player starts walking it starts taking away from one’s mood but it never stops taking away from it after the player stops, but for some reason it does for when the player stops running or jumping. (walkspeed:16)

local pl = game.Players.LocalPlayer

local UtilModule = require(game.ReplicatedStorage.Modules.Util)
local Assets = require(game.ReplicatedStorage.Modules.Assets)
local MoodModule = require(game.ReplicatedStorage.Modules.Moods)
local permsmodule = require(game.ReplicatedStorage.Modules.Permissions)

local plChar = pl.Character

pl.CharacterAdded:Connect(function(char)
	local plhuman = char:WaitForChild("Humanoid")
	plhuman:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
		print("walkspeed changed")
		if plhuman.WalkSpeed >= 21 then
			repeat
				MoodModule.DecreaseMood("Thirst",0.04,pl)
				MoodModule.DecreaseMood("Hunger",0.015,pl)
				MoodModule.DecreaseMood("Dirtiness",0.020,pl)
				MoodModule.DecreaseMood("Fatigue",0.04,pl)
				print("Removing mood for running")
				wait(1)
			until
			plhuman.WalkSpeed < 21
		elseif plhuman.WalkSpeed >= 16 and plhuman.WalkSpeed <= 18 then
			repeat
				MoodModule.DecreaseMood("Thirst",0.025,pl)
				MoodModule.DecreaseMood("Hunger",0.008,pl)
				MoodModule.DecreaseMood("Dirtiness",0.011,pl)
				MoodModule.DecreaseMood("Fatigue",0.03,pl)
				print("Removing mood for Walking")
				wait(1)
			until
			plhuman.WalkSpeed < 14
		end
	end)
	plhuman.Jumping:Connect(function(jumping)
		if jumping == true then
			repeat
				MoodModule.DecreaseMood("Thirst",0.3,pl)
				MoodModule.DecreaseMood("Hunger",0.015,pl)
				MoodModule.DecreaseMood("Dirtiness",0.20,pl)
				MoodModule.DecreaseMood("Fatigue",0.2,pl)
				print("Removing mood for jumping")
				wait(1)
			until
			jumping == false
		end
	end)
end)

Can I see your ‘ClientCore’ script?

the script above is the ClientCore

Inside your CharacterAdded() function, if you try to print char out, what does it show you?

Or you can change from this.

local plhuman = char:WaitForChild("Humanoid")

To this.

local plhuman = char:FindFirstChildWhichIsA("Humanoid")

I used to have that as the pathway to the humanoid, but it wouldn’t work with it, only WaitforChild did. (returns nill)

Then something is wrong with your Scripts in SignalGUI since it shows that ‘Infinite Yield’ possible, can you check that out?


Also this, since there is an error, so it might stop other scripts from running.

The signal Gui errors are in result of a ammo box model, which I am currently making a gui for, but doesn’t effect the any of the core scripts or the modules. Only that in particular model.

I will try to disable and see what happens

Is your Mood system script used to work before?

I belive so, yes. Also, I tried to disable the errored scripts but it didn’t change anything and the bug still continues to be a bug.

It prints out the name of both the character as well as the humanoid, so it does find them.

So if it used to work before it means that other scripts preventing your mood system from running, please make sure that all error scripts are disabled.

I think it may be my stink effect bugging it as it keeps returning an error for it, I will fix that and see.

Is this on line 96? If not, please indicate where the line 96 is since the error comes from there.

line 96 is the stink effect which I am currently fixing.

Nice! I thought that was the line 96 so my mistake for not asking first. Yep, and the error is being generated from there. Please try fixing that and see how it goes.

I have fixed the stink effect and it no longer outputs any errors, but the bug still continues to go on.

Honestly I do not understand much how your code works, but I assume that each mood will effect player’s movement speed. First, please put task.wait() instead of wait()inside your repeat function. Then you can keep tracking WalkSpeed and see if it changes. From what I can see, the value of WalkSpeed stay the same, so it won’t let you our from an infinite loop. or you can try reduce the player’s WalkSpeed without using a ModuleScript and see if the problem persists. If it works, it means that the bug comes directly from your MoodModule