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
01tab={"Player1","Noob","builderman","etc"}
02game.Players.PlayerAdded:connect(function(plr)
03    stats = Instance.new("IntValue",plr)
04    stats.Name = "leaderstats"
05    points = Instance.new("IntValue",stats)
06    points.Name = "Points"
07for i,v in pairs(tab) do--I'm pretty sure the error is somewhere from here to the end
08    Kids=game.Players:GetChildren()
09    if Kids==v then
10        Kids.leaderstats.Points.Value=9
11    end
12end
13end)

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:

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

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