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

My localscript isn't recognizing leaderstats?

Asked by
zomspi 541 Moderation Voter
5 years ago

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)



0
I would NOT use a localscript to check leaderstats my friend Creacoz 210 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)
0
That didn't work unfortunately, thanks anyone though! zomspi 541 — 5y
Ad
Log in to vote
0
Answered by
Sulu710 142
5 years ago

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!

0
That didnt work either zomspi 541 — 5y

Answer this question