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
9 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:

01model = script.Parent.Parent.Parent.Factory.D1
02cost = 0
03 
04local backup = model:Clone()
05backup.Parent = game.ServerStorage.Objects
06model:Destroy()
07 
08-- we only need what's below this line
09script.Parent.Head.Touched:connect(function(h)
10    if h.Parent.Name == game.Players:FindFirstChild(h.Parent.Name) then
11        if h.Parent.Name == script.Parent.Parent.Parent.OwnerShipSystem.Owner.Value then
12            local playername = h.Parent.Name
13            if game.Players[playername].leaderstats.Money.Value >= cost then
14                game.Players[playername].leaderstats.Money.Value = game.Players[playername].leaderstats.Money.Value - cost
15                backup.Parent = script.Parent.Parent.Parent.Factory
View all 24 lines...

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
9 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.

1if game.Players:FindFirstChild(h.Parent.Name) then
0
thanks! i didnt know it was so simple,,, davness 376 — 9y
Ad

Answer this question