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

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

Asked by
davness 376 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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
0
thanks! i didnt know it was so simple,,, davness 376 — 8y
Ad

Answer this question