Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Why are these teams not equal?

Asked by
rabbi99 520 Moderation Voter
6 months ago
Edited 6 months ago

So basically, I have a player whose team is Red. And then there's a soldier whose team is also Red. In this short script I want to compare the teams. I tested this script in team Red and right clicked on this soldier and for some reason it does not print out "Selected by same team!" And it DOES print out for print(hitterTeam) and print(soldierTeam) Red. And it also prints out "false" for print(selected). I wanna know why hitterTeam is not equal to soldierTeam.

humanoid = script.Parent
soldier = humanoid.Parent
soldierTeam = soldier.Team.Value --This is red
cd = soldier.ClickDetector
local selected

cd.RightMouseClick:connect(function(hitter)
    local hitterTeam = hitter.Team
    print(hitterTeam)
    print(soldierTeam)
    while selected == false do
        print(selected)
        wait()
        if hitterTeam == soldierTeam then
            print("Selected by same team!")
            selected = true
        end  
    end
end)

For more context, questions will be answered!

Also... even without the while loop, it would still not work!

0
I'm think you are trying to compare the teams base on the team's name. If yes, then the hitterTeam should be like this: local hitterTeam = hitter.Team.Name -- this will return the team's name. Block_manvn 393 — 6mo
0
I just realize Player.Team will return the Team object base on Player's Team. So you can do like I said before(maybe...) Block_manvn 393 — 6mo
1
Apparently that worked! Thanks lad! If you post that in the answers below I'll confirm it as the answer! rabbi99 520 — 6mo
0
I think up-vote is better :) Block_manvn 393 — 6mo

2 answers

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
6 months ago
Edited 6 months ago

soldierTeam appears to be a nil value and are not defined, hitterTeam is indexed, they are two different values and are not equal to each other.

0
soldierTeam = "Red" Forgot to mention that. So it couldn't be nil. rabbi99 520 — 6mo
1
selected is also not defined, what other errors are you having in the output? moo1210 587 — 6mo
0
Would probably help more if we saw the full script, especially the parts where things like selected and cd are defined. Torren_Mr 334 — 6mo
1
You're right! I will provide them right away. rabbi99 520 — 6mo
Ad
Log in to vote
0
Answered by
rabbi99 520 Moderation Voter
6 months ago

Okay for the people who don't understand yet. player.Team refers to game.Teams.[team the player is in] . So, it's not a string but a thing.

Answer this question