Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script if statement not working even though printing the value is corrent?

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)

1 comment

1

You are comparing a Team instance to a string which will be false each time. If you are checking the name of the team then use .Name to get the string name.

1 answer

✓ Accepted answer

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)

4 comments

0

I dont know how i missed this part :/ 3am scripting isnt the best of time to script xD. It works now, thanks!!

0

np!

0

and sorry for begging but can you please upvote my answer? im on a grind!

0

ty a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.