Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

These two values are the same but don't work in a if statement?

Asked by 6 years ago
if playerMouse.Target.Parent.Owner.Value == player.Team then

When I print either of these values they both come out as blue. The Owner.Value is a string value within a model. An if statement doesn't come out true for some reason. I have printed and know that its doing

if blue == blue then

What is wrong with this?

0
I think mouse.Target is a string and a string dosent have a b\parent IAmKingMatt -8 — 6y
1
mouse.Target is the part the mouse is on. goldstorm950 65 — 6y

1 answer

Log in to vote
0
Answered by
mraznboy1 194
6 years ago

I don't have much experience with Teams, but what I believe is happening is you're attempting to compare a string with an object. To fix this, try comparing the Value to Team.Name instead of Team.

When printing an object in roblox, the output lists its name, but the reference to the object is not actually the name. For instance, consider a part in the workspace named Part as well as a string variable Part:

local part = workspace.Part
local partString = "Part"

print(part, part.Name, partString)
print(part == partString)
print (part.Name == partString)

The first print statement would print (Part, Part, Part). However, the second statement would print out false, as it's not comparing the two directly. The third should work.

0
Oh daummmm adding .Name worked. I didn't know .Name was part of that.. Thank you. goldstorm950 65 — 6y
Ad

Answer this question