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

LocalScript "if" statement not working?

Asked by
zomspi 541 Moderation Voter
5 years ago

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

Log in to vote
0
Answered by
Vxpper 101
5 years ago

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:)

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 zomspi 541 — 5y
Ad

Answer this question