How could I disable the reset button except for when players are in the "lobby"?

I add an attribute when the player joins the game, like this:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
    plr:SetAttribute("InGame", false)
end)

Basically while this attribute is false I want the reset button to be enabled, but while it is true, I want it to be disabled.

My reset button script is here:

-- Roblox Services
local StarterGUI = game:GetService("StarterGui")

-- Disables the Reset Button
----[ Creates a Loop to make sure that the ResetButtonCallBack works.
repeat 
	local success = pcall(function() 
		StarterGUI:SetCore("ResetButtonCallback", false) 
	end)
	task.wait(1)
until success
1 Like

You can use GetAttributeChangedSignal.

local sGui = game:GetService("StarterGui")
local player = game:GetService("Players").LocalPlayer

repeat task.wait() until player:GetAttribute("InGame")

local function update()
    local newValue = player:GetAttribute("InGame")
    local newState = false
    if newValue == true then --can't use logic statement because it will check if the attribute exists or not
        newState = false
    else
        newState = true
    end
    
    sGui:SetCore("ResetButtonCallback", newState)
end

player:GetAttributeChangedSignal("InGame"):Connect(update)
1 Like

Ah thats perfect, thank you very much for your help :slight_smile:

2 Likes

Hi, sorry I’m having some issues with the update function getting called. My attribute value definitely changes to true when the player is “InGame”. I added some print statements and as expected the “Waiting” one prints. However the “updated” one doesn’t.

local sGui = game:GetService("StarterGui")
local player = game:GetService("Players").LocalPlayer

repeat task.wait() until player:GetAttribute("InGame")

print("Waiting")

local function update()
	print("Updated")
	local newValue = player:GetAttribute("InGame")
	local newState = false
	if newValue == true then --can't use logic statement because it will check if the attribute exists or not
		newState = false
	else
		newState = true
	end

	sGui:SetCore("ResetButtonCallback", newState)
end

player:GetAttributeChangedSignal("InGame"):Connect(update)

are you sure that player has an attribute called “InGame” and that you’re changing it by using Player:SetAttribute() ?

game.Players.PlayerAdded:Connect(function(player) 
	
	local success, owned = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, player.UserId, 98681915)

	if success and owned then
		--they own the pass
		player:SetAttribute("GamepassOwned", true)
	elseif not success then
		player:Kick("Failed to retrieve gamepass data. Please rejoin!")
	else
		--they don't own the pass
		player:SetAttribute("GamepassOwned", false)
	end
	
	player:SetAttribute("Kills", 0)
	player:SetAttribute("Deaths", 0)
	player:SetAttribute("InGame", false)
for i = #gamePlayers, 1, -1 do
		gamePlayers[i]:SetAttribute("InGame", true)
	end

Not sure if this could work, but because you’re using SetAttribute, it might be adding an attribute instead of updating an existing one. Try player:GetAttribute("InGame") = true.

Not tested it, so I’m not too sure :confused: .

1 Like

everything seems fine so far, maybe check this part;

try to print it or something, does it actually get the player and change its attribute, maybe it refers to something else

Yeah I checked and it definitely works. As 1234koip said, I think its to do with im not actually updating the value, I’m creating a new one.

as long as the index is the same, you do not create a new attribute, and you can’t change the attribute by using :GetAttribute(), thats solely for getting the current attribute value

1 Like

I ended up using this code, except for I fired a remote event from the server when the value updated, and that worked perfectly. Thank you both for your help :slight_smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.