Am making a Hunger Script rn but it just doesn’t work and doesn’t show any errors any help is appreciated!! (btw the attribute is created on another script)
Script:
local Module = require(game.ReplicatedStorage.Modules.Hunger)
game.Players.PlayerAdded:Connect(function(plr)
print("yes")
while task.wait(0.1) do
plr:SetAttribute("Hunger", plr:GetAttribute("Hunger") - Module.HungerDrain)
if plr:GetAttribute("Hunger") <= Module.HungryStart then
plr:SetAttribute("Hungry", true)
else
plr:SetAttribute("Hungry", false)
end
if plr:GetAttribute("Hunger") <= Module.MinHungerValue then
plr:SetAttribute("Hunger", Module.MinHungerValue)
end
if plr:GetAttribute("Hunger") >= Module.MaxHungerValue then
plr:SetAttribute("Hunger", Module.MaxHungerValue)
end
end
end)
local Module = require(game.ReplicatedStorage.Modules.Hunger)
game.Players.PlayerAdded:Connect(function(plr)
print("yes")
plr:SetAttribute("Hunger", Module.MaxHungerValue)
plr:SetAttribute("Hungry", false)
while task.wait(0.1) do
plr:SetAttribute("Hunger", plr:GetAttribute("Hunger") - Module.HungerDrain)
if plr:GetAttribute("Hunger") <= Module.HungryStart then
plr:SetAttribute("Hungry", true)
else
plr:SetAttribute("Hungry", false)
end
if plr:GetAttribute("Hunger") <= Module.MinHungerValue then
plr:SetAttribute("Hunger", Module.MinHungerValue)
end
if plr:GetAttribute("Hunger") >= Module.MaxHungerValue then
plr:SetAttribute("Hunger", Module.MaxHungerValue)
end
end
end)
a task.spawn is like a script inside a script. So anything inside a task.spawn would run while the rest of the script is running, so it’s good for while loops so they don’t yield and stop the script. It’s like a coroutine.
Sorry if my explanation was bad lol, you can search it up if you want.