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

(Probably a very obvious mistake) Why won't this work?

Asked by
tumadrina 179
10 years ago
tab={"Player1","Noob","builderman","etc"}
game.Players.PlayerAdded:connect(function(plr) 
    stats = Instance.new("IntValue",plr) 
    stats.Name = "leaderstats" 
    points = Instance.new("IntValue",stats)
    points.Name = "Points" 
for i,v in pairs(tab) do--I'm pretty sure the error is somewhere from here to the end
    Kids=game.Players:GetChildren()
    if Kids==v then
        Kids.leaderstats.Points.Value=9
    end
end
end) 

nothing in the output and when the people in the table enter,nothing happen

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

In line 9 of that code snippet, you are comparing a Table (game.Players:GetChildren()) with a a String (v, which in this context is a member of that table tab, of which all are Strings). That if statement will always not go through.

I assume you want to check if the player that just joined is on that list, and if so give them 9 points:

tab={"Player1","Noob","builderman","etc"}
game.Players.PlayerAdded:connect(function(plr) 
    stats = Instance.new("IntValue",plr) 
    stats.Name = "leaderstats" 
    points = Instance.new("IntValue",stats)
    points.Name = "Points" 
    for i,v in pairs(tab) do
        if plr.Name == v then
            points.Value = 9 -- Since I assume it is plr you're wanting to give points to, we already have their Points IntValue object.
        break -- no need to continue looping if we get a match.
        end
    end
end) 

Also, try to use spaces before and after all operands (including the string concatenation one: ..) Errors sometimes popup because a phrase you intended to be separate was considered one word by the interpreter, and it also looks a little cleaner. This is not a requirement, as you code is correct without the spaces.

0
Thanks, I always make the dumbest mistakes my bad :) tumadrina 179 — 10y
Ad

Answer this question