I've been working on an AFK check thingy for my game so players can't just autoclick all day, and when I test it, the button doesn't work. I've tried MouseButton1Click and MouseButton1Down and neither seem to work. Nothing shows in the output so I think it should work, but I don't know.
Example (The bin thing is a DataStore problem, don't worry about that)
My code
Problem is at lines 21-26
Player = game.Players.LocalPlayer
AFKCheckFrame = script.Parent
while true do
wait(math.random(10, 15))
AFKCheckFrame.Visible = true
local afkchecknum = 0
local randomafk = math.random(10,20)
while afkchecknum <= randomafk do
wait(1)
local randomx = math.random(0, 312)
local randomy = math.random(0, 629)
AFKCheckFrame:TweenPosition(UDim2.new(randomx/1000, 0, randomy/1000, 0), "Out", "Quad", math.random(1, 5))
afkchecknum = afkchecknum + 1
AFKCheckFrame.TextLabel.Text = "you better not be afking on this masterpiece of a game. you have ["..randomafk-afkchecknum.."] seconds to click that you're not!"
end
AFKCheckFrame.TextButton.MouseButton1Down:connect(function()
if afkchecknum <= randomafk then
AFKCheckFrame.Visible = false
randomafk = 1000000
end
end)
if afkchecknum >= randomafk then
Player:Kick("you have been afk for too long")
end
AFKCheckFrame.Visible = false
end

2 comments
Move the MouseButton1Click event to before the while loop. The while loop will not be exited until it is terminated in some way.
But I want it to do that as I want it to check every few minutes, not just once. Therefore I need the loop