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