Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My localscript isn't recognizing leaderstats?

This script works in studio but not roblox itself, I don't know what's wrong?

local button = script.Parent
game.Players.PlayerAdded:Connect(function()

local purchases = game.Players.LocalPlayer:WaitForChild("leaderstats1"):WaitForChild("Purchases2")


    if purchases.Value == 3 then
        print("MVP")
        button.Visible = true
        button.Parent:WaitForChild("MVP1"):WaitForChild("TextLabel").Visible = false
    else
        print("Bye")
        button.Visible = false
    end
end)



1 comment

0

I would NOT use a localscript to check leaderstats my friend

2 answers

try using game:GetService(Players') for every time you reference the Players in the game. Here's your copy of the script but edited:

local button = script.Parent
game:GetService('Players').PlayerAdded:Connect(function()

local purchases = game:GetService('Players').LocalPlayer:WaitForChild("leaderstats1"):WaitForChild("Purchases2")


    if purchases.Value == 3 then
        print("MVP")
        button.Visible = true
        button.Parent:WaitForChild("MVP1"):WaitForChild("TextLabel").Visible = false
    else
        print("Bye")
        button.Visible = false
    end
end)

1 comment

0

That didn't work unfortunately, thanks anyone though!

This script shouldn’t have the “player added function”. Right now every time a player is added, it checks the local player’s stats, not that of the player who is being added. Instead, your script should say:

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local button = script.Parent

local purchases = player:WaitForChild("leaderstats1"):WaitForChild("Purchases2")

if purchases.Value == 3 then
     print("MVP")
     button.Visible = true
     button.Parent:WaitForChild("MVP1"):WaitForChild("TextLabel").Visible = false
else
     print("Bye")
     button.Visible = false
     end
end)

Without having the player added function, the script will run when the player joins the game (or when the local script gets replicated which is usually pretty soon after), instead of it waiting until another player joins the game for it to run. Hope this helped!

1 comment

0

That didnt work either

This discussion is preserved as it was. New answers, comments, and votes are closed.