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

Plr is not a valid member of Players?

Asked by 9 years ago
script.Parent.Catch.Touched:connect(function(otherPart)
    print(otherPart)
    local plr = script.Parent.Parent.Parent.OwnerName.Value
    local turninprice = otherPart.Parent.turninprice.Value 
        if otherPart.Parent.Parent == script.Parent.Parent.Parent.MoneyBricks then 
            otherPart:Destroy()
            print ("Part deleted")
            print (plr)
            game.Players.plr.leaderstats.Money.Value=plr.leaderstats.Money.Value+turninprice
    end
    end)

08:31:27.072 - plr is not a valid member of Players 08:31:27.072 - Script 'Workspace.Tycoon.ConveyorLine1.Catcher.Catcher', Line 9

This is the error I receive when the script is trying to work, I've established the variable as plr, and even when it prints "plr" it prints Player1, however when I try to call the variable on line 9, it doesn't establish that game.Players.plr is supposed to mean game.Players.player1 (or whoever's name is on the OwnerName value)

Any help would be appreciated, thanks!

2 answers

Log in to vote
1
Answered by 9 years ago

Your issue is that you are trying to access the property/member of game.Players called plr. However, that doesn't exist. You need to replace this:

game.Players.plr.leaderstats.Money.Value=plr.leaderstats.Money.Value+turninprice

with this:

game.Players[plr].leaderstats.Money.Value=plr.leaderstats.Money.Value+turninprice

That way, you're instead accessing the member with the name contained in the variable plr.

Ad
Log in to vote
1
Answered by 9 years ago

Your trying to find 'plr' inside players The children of game.Players are the people in the game.

local player = gamer.Player:FindFirstChild("plr")
if player then
player.leaderstats.Money.Value=plr.leaderstats.Money.Value+t
end
0
If I modify my script with what you said, I receive the error, "09:57:59.343 - Player is not a valid member of DataModel" and the leaderstats are not added carcanken 65 — 9y

Answer this question