Player not on team but script continues

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

hoping someone knows how to fix this!

should not the condition be

if Player.Team == Teams["Luxury - 1"] or Player.Team == Teams["Masonry - 2"] then

?

1 Like

nope, ive tried it and it produces the same result

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!

im a bit confused, wdym by check suggestion?

He means what he provided (this, suggestion)

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!

ive actually changed the code a bit so its actually

if Player.Team ~= Teams["Nominees -"] or Player.Team ~= Teams["Host -"] then


it knows im on the nominee team, but is still continuing the script

That’s (if Player’s team is not equal to Teams["Nominees -"]or Player’s team is not equal to that Teams["Host -"] then do code end)

it’s running because if player's team is not equal to either to that team or to that team then do code end

wdym by it’s running because player’s team is not equal to either to that team or to that team?

if Player.Team ~= Teams["Nominees -"] or Player.Team ~= Teams["Host -"] then

Runs because Player’s team is not equal to Teams["Nominees"], you need to make if it’s equal the == and that’s it, check it

Better both

if Player.Team ~= Teams["Nominees -"] or Player.Team == Teams["Nominees -"] then

like this?

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
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.