im having some issues with my code, ive already made it so the localscript would check if the player is a on specific team. but the script ignores it and continues it anyway instead of waiting. here’s my code:
while true do
if Player.Team == Teams["Luxury - 1"] or Teams["Masonry - 2"] then
repeat
print(Player.Name.. " from ".. "Luxury Or Masonry".." is losing hunger.")
task.wait(1)
HungerBar = HungerBar - 1
Check = false
Gui.Hunger.Stat.Text = HungerBar
if HungerBar == 0 then
print(Player.Name.. " has died from hunger")
Player.Character.Humanoid.Health = 0
else
print(Player.Name.. "'s hunger is currently " ..HungerBar)
end
until HungerBar == 0
else
task.wait(0.1)
end
end
Welp, this condition if Player.Team == Teams["Luxury - 1"] or Teams["Masonry - 2"] then
checks if player’s team is equal to Teams["Luxury - 1"] or Teams["Masonry - 2"] is true.
If the latter is not nil or boolean which is true then the whole condition evaluates to true resulting in impression that player is in a team.
Whilst suggested change checks if player’s team is equal to either one team or another from Teams.
Could you please check suggestion once more?
Thank you!
if Player.Team == Teams["Luxury - 1"] or Player.Team == Teams["Masonry - 2"] then
@af_2048 Posted right code of checking if player’s team is equal to that team (not if that Teams exists)
basically you added if Teams["Masonry - 2"] (exists) then (do code), not if player’s team is equal to that team.
Can you provide us video showing the problems and perhaps with logs
nvm, my bad, I missed your point.
Could you please print player’s team and teams in Teams table?
That would give you a hint why condition does not work.
Thanks!
turns out, all that needed to be changed was the “or” in the script, it works perfectly fine if you replaced it with and. thank you for helping me anyways!
if Player.Team ~= Teams["Nominees -"] and Player.Team ~= Teams["Host -"] then
Your previous issue with previous code was because of your checking if that Teams[“Masonry - 2”] then it would do code, the solution was change the Teams["Masonry - 2"] to plr.Team == Teams["Masonry - 2"] and that’s it
(fixed)
while true do
if plr.Team == Teams["Luxury - 1"] or plr.Team == Teams["Masonry - 2"] then
repeat
print(plr.Name.. " from "..plr.Team.Name.." is losing hunger.") -- if you want to know which player is in team
task.wait(1)
HungerBar = HungerBar - 1
Check = false
print(plr.Team.Name) -- added to check what team, is the player in
if HungerBar == 0 then
print(plr.Name.. " has died from hunger")
plr.Character.Humanoid.Health = 0
else
print(plr.Name.. "'s hunger is currently " ..HungerBar)
end
until HungerBar == 0
else
task.wait(0.1)
print("not running") -- this is added for checking if code is not runned due to if condition was not true (the up)
end
end