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

LocalScript "if" statement not working?

My local script to see the value of leaderstat isn't working. Do I need to make it server script with remote events? Here is my script:

game.Players.PlayerAdded:connect(function()

    if game.Players.LocalPlayer.leaderstats.Purchases.Value == 1 then

        print("Hi")

        game.StarterGui.ScreenGui.Frame1.Desert.Visible = true

    else

        game.StarterGui.ScreenGui.Frame1.Desert.Visible = false

end

end)

Thanks!

1 answer

This is the code you wrote:

game.Players.PlayerAdded:connect(function()

    if game.Players.LocalPlayer.leaderstats.Purchases.Value == 1 then

        print("Hi")

        game.StarterGui.ScreenGui.Frame1.Desert.Visible = true

    else

        game.StarterGui.ScreenGui.Frame1.Desert.Visible = false

end

end)

Let us make some fixes!

The only fix that is needed is the game.StarterGui.ScreenGui.Frame1.Desert.Visible and also game.Players.PlayerAdded if you want this to check whenever the player gets 1 purchase.

This usually is never used, instead, use this: I'm gonna make a variable to shorten the game.Players.LocalPlayer.

local player = game.Players.LocalPlayer

player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible = 

Now with our fixed code the final code should be:

local player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function() -- You could just use a while wait(.1) but that is inefficient. Although this is when the player joins it checks the following code.

    if player.leaderstats.Purchases.Value == 1 then

        print("Hi")

        player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible = true

    else

       player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible = false

end

end)

If you have any more questions please feel free to comment more than happy to help:)

1 comment

0

Unfortunately that didn't work either, here is what I want it to look like but none of the scripts I have tried work: This is what it looks like: https://ibb.co/0MmHShY and this is what it's supposed to look like: https://ibb.co/NYRpngM

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