Why wont my afk button wont work

For some reason my afk button wont work

script.Parent.MouseButton1Click:Connect(function(click)
	print("hi")
	script.Parent.Button:Play()
	local player = game.Players:WaitForChild("LocalPlayer")
	local afk = player.Afk
	print(afk.Value)
	if game.Players.Afk.Value == false then
		game.Players.LocalPlayer.Afk.Value = true
		script.Parent.Text = "UnAfk"
		if game.Players.LocalPlayer.Afk.Value == true then
			game.Players.LocalPlayer.Afk.Value = false
			script.Parent.Text = "Afk"
		end
	end
end)
3 Likes

Are there any console errors? .

1 Like

Nope no console errors at all cause Idk why

1 Like

Also its not the game.Players.Afk.Value mistake nope

1 Like
local button = script.Parent
local afk = player.Afk
local player = game.Players.LocalPlayer


button.MouseButton1Click:Connect(function()
	
	if player.Afk.Value == false then
		afk.Value = true
		button.Text = "UnAfk"

    elseif player.Afk.Value == true then
		afk.Value = false
		button.Text = "Afk"
	end

end)```
1 Like

Your error is that It checks whether its false, turns it to true, then checks whether its true, then turns it back to false, so nothing happens

1 Like

Oh but I get a index error now

paste the entire console error here

I fixed the errors lol sorry I just forgot to add some locals

Great! do remember to mark the appropriate answer as the solution so people know its solved.

Thank you for helping with my code