If statement meets all conditions but doesn't work?

The title is exactly my question…

			
local owner = script.Parent.Parent.Parent.Owner
			
print(player.Name.. " THIS IS NAME OF PLAYER")
print(tostring(owner.Value).. " THIS IS VALUE OF OWNER")
			
if player.Name == owner.Value then 	
    print("is owner")
else
    print("is not owner")
end

My code right here is printing out my full username and the owner value. They are identical.

Though… It still goes with is not the owner… I’m generally so confused with this little tiny thing?

image

Why is this happening?

1 Like

try using string.lower

local owner = script.Parent.Parent.Parent.Owner
			
print(player.Name.. " THIS IS NAME OF PLAYER")
print(tostring(owner.Value).. " THIS IS VALUE OF OWNER")
			
if string.lower(player.Name) == string.lower(owner.Value) then 	
    print("is owner")
else
    print("is not owner")
end

No to string here:

But not here

Why is that? Could that be why? What kind of value is owner

I’d suggest using an int value as the value and set it to the Owners UserId and then check if it matches the players userid
Player names can change, player ids NEVER change

Here is an example

SET INT VALUE TO PLAYER ID

local Owner = script.Parent.Parent.Parent.Owner

print(Owner.Value .. ", is the game creators UserId")

if Owner.Value == Player.UserId then

    print("Player is Owner")

else

    print("Player is a Guest")

end

I replied to a comment on accident*

Could we see :
What type of value is ‘Owner’?
Here I assume it is either a NumberValue or an IntValue.

Also try this:

local owner = script.Parent.Parent.Parent.Owner
		
print(player.Name.. " THIS IS NAME OF PLAYER")
print(owner.Value).. " THIS IS VALUE OF OWNER")
print(owner.Value) -- does it print?
			
if owner.Value == player.UserId then --alternatively, you could compare with their name.	
    print(player.Name.."is owner")
else
    print(player.Name.."is not owner")
end

But overall, we’d like to see what ‘owner’ is.

small mistake there
don’t forget to remove the first ‘)’ after the .Value :wink:

Instead of using a stringvalue for the owner name, replace it with just a variable:

local owner = 'Your Username'
if player.Name == owner then
-- do whatever
else
-- do whatever
end

If the owner value is an ObjectValue with yourself in it, you will have to do:

if player.Name == owner.Value.Name then
1 Like

This worked perfectly!

Thankyou!

It was an ObjectValue :slight_smile:

2 Likes

if player == owner.Value would be better. While unlikely, a player could change their username mid-game.

I am pretty sure the owner value is probably for the owner of the vehicle or something like a tycoon owner. Not the owner of the game. Which is why he cannot set a string like that.

Ahh. Thanks for pointing that out.

1 Like