I made an afk mode button and the text is supposed to change. Here is the script:

This creates the afk value:

local AfkMode
local playerSettings

local players = {}

game.Players.PlayerAdded:Connect(function(player)
	table.insert(players, player.Name)
	
	-- Settings for the player
	playerSettings = Instance.new("Configuration")
	playerSettings.Name = "Settings"
	playerSettings.Parent = player
	
	-- Afk
	AfkMode = Instance.new("BoolValue")
	AfkMode.Name = "Afk"
	AfkMode.Parent = playerSettings
	AfkMode.Value = false
end)

And this changes the text on the button (on/off):

game.StarterGui.Settings.AfkModeButton.MouseButton1Click:Connect(function(player)

	local AfkModeButton = player.PlayerGui.Settings.AfkModeButton
	local AfkMode = player.Settings.Afk

	AfkMode = not AfkMode.Value

	if AfkMode.Value == false then
		AfkModeButton.Text = "AFK Mode: Off"
	elseif AfkMode.Value == true then
		AfkModeButton.Text = "AFK Mode: On"
	end
end)

Nothing happens when I click, whats wrong?

1 comment

0

That's because you're referencing the template in StarterGui. You should be referencing the one in PlayerGui.