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

Leaderstat script works very well in Studio, but not ingame?

Asked by 6 years ago

Please help. This is like the fourth time I've posted this question and twice it has been wrongfully moderated by this joke of a moderation team and 0 of the times the question has correctly been answered. (If this is taken down before it has been answered it will be reposted. Just sayin) Anyway. This is one of my scripts. It is supposed to take the value of Videos and add it to the value of Views every 2 minutes. It works perfectly in Studio, but not the game it is on. I have tried using WaitForChild, doesn't work still. If anyone wants to see the game it is on, here it is: https://web.roblox.com/games/1300877434/OPEN-Be-a-YouTuber-ALPHA#!/about I don't know if that will help answer my question or not, but just in case I put it there. Better to be safe than sorry. Here is my script:

while wait(120) do
for _,player in pairs(game.Players:GetChildren()) do
if player:FindFirstChild("leaderstats")then
if player.leaderstats.Subscribers.Value <= 10 then
player.leaderstats.Views.Value = player.leaderstats.Views.Value + player.leaderstats.Videos.Value
end
end
end
end
end)

0
Just what are you trying to do? NetworkEngineer 0 — 6y
0
did you read the post? sesamert16 31 — 6y
0
Is this being run on the client or the server? Gey4Jesus69 2705 — 6y
0
Dont bother. He never reads his comments or anything. decla123 45 — 6y

1 answer

Log in to vote
0
Answered by
dqxs 15
6 years ago
while wait(120) do
    for _, player in pairs(game:GetService("Players"):GetChildren()) do
    -- Use :WaitForChild(), since when you join the leaderstats needs to load first.
    local leaderstats = player:WaitForChild("leaderstats")
    local subs = leaderstats:WaitForChild("Subscribers")
    local Views = leaderstats:WaitForChild("Views")
    local Videos = leaderstats:WaitForChild("Videos")
    local num = 10
    if subs.Value <= num then
        Views.Value = Views.Value + Videos.Value
    end
end
Ad

Answer this question