Hi, I’ve been thinking and I want a GUI to appear when entering the game for the first time, and when you die or exit and log in, you will never have the GUI again. That I have to do?
Turn off resetonspawn
- On your exit button make sure to destroy the GUI for example
script.Parent.MouseButton1Click:Connect(function()
yourstartergui:Destroy()
end)
Is this what you mean, if so mark this as a solution
I think he meant a startup GUI. When you first enter a game, the GUI pops up. But when you rejoin, it doesn’t. For that you can use DataStore, to check if the player has seen the UI or not. if so, destroy the UI, locally.
Oh, now that I read it again, I see my bad, lol.
Exactly, that’s what I mean, do you know any solution?
Use this, it should help you anytime
Enable API services through game settings > security.
You can set up the GUI creation yourself but, this is just a rough basis of what you should do for the datastore part.
Sorry for the bad indentation or any typos, I had to write this fully in the reply section.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MyDataStore_001"))
local Players = game:GetService("Players")
local function isNew(Player)
local plrData
local success, err = pcall(function() -- no need to go too crazy with data loss prevention, simple pcall
plrData = DataStore:GetAsync(Player.UserId)
end)
if err or not plrData or plrData == nil then --if it errored, plrdata is false, or it's nil, then show gui
return true --player is new!
local success, err = pcall(function()
plrData = DataStore:SetAsync(Player.UserId, true) --we showed the gui, player shouldnt see it again so we save info in ds
end)
elseif plrData == true then
return false --player is NOT new
end
end
I’m sorry I’m late, I’ve been busy. Well, I have 2 problems, one is that it gives me the following error
I managed to resolve an error above, but this cannot resolve it. My other problem is that I don’t know how to make the GUI retrieve the script
You can use
game.Players.PlayerAdded
This way, they will have the UI only appear when they join (you’ll manually clone the UI in their player Gui.
So sorry, the issue was that I did return and then attempted to save data, returning sort of marks the end of the scope.
I fixed this up and it should work entirely, hopefully you can learn something from it.
Script goes in ServerScriptService, with the GUI inside the script. Make sure you label the GUI in the script.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MyDataStore_002") -- Name can be anything.
local Players = game:GetService("Players")
local UI = script["YOURUINAME"] -- Put your UI name here
local function isNew(Player)
local plrData
local success, err = pcall(function() -- no need to go too crazy with data loss prevention, simple pcall
plrData = DataStore:GetAsync(Player.UserId)
end)
if err or not plrData or plrData == nil then --if it errored, plrdata is false, or it's nil, then show gui
local success, err = pcall(function()
plrData = DataStore:SetAsync(Player.UserId, true) --we showed the gui, player shouldnt see it again so we save info in ds
end)
return true --player is new!
elseif plrData == true then
return false --player is NOT new
end
end
function onPlayerAdded(Player)
local newCheck = isNew(Player) -- Function either returns true or false
if newCheck then -- If it's true, we run this, otherwise we don't.
local newUI = UI:Clone()
UI.Parent = Player.PlayerGui
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded) -- Connect the player added event to the function