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

How to make a main menu that only appears when the player joins the game for the first time?

Asked by 2 years ago

I want to make a main menu that will only show the first time a player plays my game but everything I tried won't work. Right now I have a bool that detects if the player has joined the game before or not and that is working but the script that hides and shows the GUI won't work.

This is the script I am using. It is a local script inside of starter player scripts.

local mainMenu = game.StarterGui.TitleScreen
local onMenu = player:WaitForChild("onMenu")
local isLoaded = game.ReplicatedStorage.Value

if onMenu.Value == true then
    mainMenu.Enabled = true
else
    mainMenu.Enabled = false

end

2 answers

Log in to vote
1
Answered by
MattVSNNL 620 Moderation Voter
2 years ago

Hello, Your LocalScript is fine!

But if we want to know if the player had joined once and is returning, whe use something called DataStore, DataStore is a service that allows you to save a table or value forever!

Create a Script in ServerScriptService and call it whatever you want

If the script works, I'd highly appreciate it if you accept my answer, otherwise if it doesn't work, comment the problem and I'll try and fix it!

Script in ServerScriptService:

local PlayersService = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")

local joinDataStore = dataStoreService:GetDataStore("JoinDataStore")

PlayersService.PlayerAdded:Connect(function(player)

    local isOnMenu = Instance.new("BoolValue")
    isOnMenu.Name = "onMenu"
    isOnMenu.Parent = player

    local playerJoinData = nil

    pcall(function()
        playerJoinData = joinDataStore:GetAsync(player.UserId.."-joinData")
    end)

    -- If player had joined once!
    if playerJoinData ~= nil then

        isOnMenu.Value = false
        print("Returning player")
    else
        isOnMenu.Value = true
        print("New player")
    end

end)

local bindableEvent = Instance.new("BindableEvent")

PlayersService.PlayerRemoving:Connect(function(player)

    pcall(function()
        joinDataStore:SetAsync(player.UserId.."-joinData", player.onMenu.Value)
    end)

    bindableEvent:Fire()
    print("Saved!")

end)

game:BindToClose(function()
    while #PlayersService:GetPlayers() > 0 do
        bindableEvent.Event:Wait()
        wait()
    end
end)
0
Also you can use badge and then test if player have it Shish20101 22 — 2y
0
That costs Robux MattVSNNL 620 — 2y
Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Answer this question