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