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

TYCOON WORK 0002: Script keeping saying a player isn't a player, Why???!

Hello. I am making a tycoon and I was making a button when I decided to test it. And to check the working of it, I decided to make some prints:

model = script.Parent.Parent.Parent.Factory.D1
cost = 0

local backup = model:Clone()
backup.Parent = game.ServerStorage.Objects
model:Destroy()

-- we only need what's below this line
script.Parent.Head.Touched:connect(function(h)
	if h.Parent.Name == game.Players:FindFirstChild(h.Parent.Name) then
		if h.Parent.Name == script.Parent.Parent.Parent.OwnerShipSystem.Owner.Value then
			local playername = h.Parent.Name
			if game.Players[playername].leaderstats.Money.Value >= cost then
				game.Players[playername].leaderstats.Money.Value = game.Players[playername].leaderstats.Money.Value - cost
				backup.Parent = script.Parent.Parent.Parent.Factory
				print("Transaction completed! :)")
				script.Parent:Destroy()
			else print ("The owner hasn't money...")
			end
		else print ("This player isn't the owner")
		end
	else print("This isn't a player")
	end
end)

But when I step with an player on it, it says always "This isn't a player" Why??? Need more info?

1 answer

✓ Accepted answer

if h.Parent.Name == game.Players:FindFirstChild(h.Parent.Name) then

You're comparing a string with an object!, hit.Parent.Name is a string and game.Players:FindFirstChild(h.Parent.Name) is going to be the player object. They will never match even if the player exists.

You should just check if game.Players:FindFistChild(h.Parent.Name) exists.

if game.Players:FindFirstChild(h.Parent.Name) then

1 comment

0

thanks! i didnt know it was so simple,,,

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