Hi Guys,
I have a script that will basically check if the player is not on the team named "Passenger". If they are not on it, it will print that they can spawn, whereas if they are on the team it will print that they cant spawn. Could someone help me because all it seems to do is just go to the else part and doesn't ever fulfill the if statement, even though i am 100% sure it does. Script is below, any advice would be great!
script.Parent.Spawn.TextButton.MouseButton1Click:Connect(function() print(game.Players.LocalPlayer.Team) if game.Players.LocalPlayer.Team ~= "Passenger" then print("Can spawn bus") else print("Can NOT spawn bus") end end)
What kingdom said is the exact issue you're facing. It's true that printing
game.Players.LocalPlayer.Team
will return the team's name, but that is actually not a string, it is returning the Instance by showing its name. And yiy are comparing an Instance to a string, and that is obviosuly false. So what you gotta do is get the team's name, which is a string value, and thenn the checking if the team's name is == to "Passenger" will do its thing. Always watch out from this instance/string thing.
script.Parent.Spawn.TextButton.MouseButton1Click:Connect(function() print(game.Players.LocalPlayer.Team.Name) --you can add a .Name here and you'll see that it'll print the same thing, but without the .Name it will return the instance, with it will return a string. if game.Players.LocalPlayer.Team.Name ~= "Passenger" then print("Can spawn bus") else print("Can NOT spawn bus") end end)