Place Visits applies changes to GUI Frame


I would like to achieve something along with the images of the following.


I have made an IntValue that connects Value with the amount of Place Visits that a Player has.
I have therefore made it plr.leaderstats.Visits.Value.
I’m trying to make the number of place visits impact the GUI that the Player receives.

I can use if plr.leaderstats.Visits.Value >= 10000 then

This script is stored in ServerScriptService, It is a normal script. It doesn’t work. Help me fix it.

function verifyVisits(player)
    if player.leaderstats.Visits.Value >= 10000 then
    	game.Workspace.Part.ProximityPrompt.Enabled = true
    	game.StarterGui.ScreenGui2.VisitAnswer3.Visible = false
    	game.StarterGui.ScreenGui1.VisitAnswer2.Visible = true
    else return "NotTrue" end
end

game.Players.PlayerAdded:Connect(function(plr)
    -- Data store code and value instancing goes here
    if verifyVisits(plr) == "NAN" then 
        plr.leaderstats.Visits.Changed:Connect(function()
            verifyVisits(plr)
        end)
    end
end)

This showed up in my Output.
why
However, I can assure you that I do have it.
see

Please help me out. I’ve been trying to search everywhere if there is a solution or if anyone has done it before. I couldn’t find a thing.

What I am trying to do is making a game called the System in which it is like a fortune teller and it challenges you.


1 Like

You need to wait for leaderstats to be created, it’s erroring because it’s not made by the time the event is ran

game.Players.PlayerAdded:Connect(function(plr)
    -- Data store code and value instancing goes here
    if verifyVisits(plr) == "NAN" then 
        plr:WaitForChild("leaderstats").Visits.Changed:Connect(function()
            verifyVisits(plr)
        end)
    end
end)

Edit: To add onto what @JackscarIitt mentioned, you need to reference the playergui rather than the startergui, in your function, try this instead

function verifyVisits(player)
    if player.leaderstats.Visits.Value >= 10000 then
        local gui = player.PlayerGui
    	game.Workspace.Part.ProximityPrompt.Enabled = true
    	gui.ScreenGui2.VisitAnswer3.Visible = false
    	gui.ScreenGui1.VisitAnswer2.Visible = true
    else return "NotTrue" end
end
1 Like

Try doing

plr:WaitForChild("leaderstats")

? Another thing as well

Is that you’re only changing the StarterGui which only reflects on the server, might wanna change that to PlayerGui instead

1 Like