Hello there! Well to begin try simplifying the script to a much easier use than the generic for loop, refer to this link for some help with loops. The one I will be referring to is the second example in the for loop section. This is a way to go through an array/table without the more complicated for i = 1, number do loop (First Example).
To start lets start by simplifying the while loop.
local PointTime = 10
while wait(PointTime) do
end
So, to explain what I just did, is instead of using a bit more complicated generic* while loop, I replaced the true statement with a wait. This runs the loop everytime the wait reaches the time we set :)
local PointTime = 10
while wait(PointTime) do
for num, obj in pairs(game.Players:GetChildren()) do
if (obj:IsA("Player")) then
end
end
end
You may be wondering," What Just Happened!" Let's take this slow and I'll explain this. So what we added is a for loop, which cycles or goes through the entire Players part of the game. The num refers to the current index, the number of the obj based off the array/table. The obj is the Object currently being scanned*. So the next thing is dealing with the obj:IsA("Player") bit. This returns true if the object is in the class "Player". Now lets check if the player has the correct leaderstats.
local PointTime = 10
local PointsGiven = 20
while wait(PointTime) do
for num, obj in pairs(game.Players:GetChildren()) do
if (obj:IsA("Player")) then
if (obj:IsInGroup(2534776)) then
PointsGiven = PointsGiven + 5
end
if (obj:findFirstChild("leaderstats") and obj.leaderstats:findFirstChild("Ducat")) then
obj.leaderstats.Ducat.Value = obj.leaderstats.Ducat.Value + PointsGiven
end
end
end
end
To explain what we just added, simply is making sure the player has the correct things and see if the player is in the specific group. The checking of the group won't be explained, as it seems you understand it, but go here, for a refresher. The if statement is used to make sure both the leaderstats and Ducat are in the there and aren't nil.
If you still need the second leaderstats, I'll leave that to you so you get some hands on work. If this doesn't work, please tell me what happened :)
4 comments
For Line number 6 it says "Workspace.Script:6: 'in' expected near '='." Is there something wrong?
Hmm let me test this further and I'll report back asap
Okay, and thank you so much for the explanation. I'm sure I'll put your help to good use
Ah, I've found the problem. The post has been updated and should work with no errors now :)