I want to make an automation button feature in a clicker game.
It’s not working when it seems correct to me, this has happened quite a few times whilst trying to script UI.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local StarterGUI = game:GetService("StarterGui")
local ScreenGUI = StarterGUI:WaitForChild("ScreenGui")
local autoPunch = ScreenGUI:WaitForChild("AutoPunch")
local deb = false
local auto = false
autoPunch.MouseButton1Click:Connect(function()
if auto == false then
auto = true
while auto == true do
Player.leaderstats.Punches.Value += 1
wait(1)
auto = false
end
end
end)
The script is a local script and is placed under ScreenGUI.
I removed this and it didn’t work, I modified the the function a bit and it still didn’t work.
autoPunch.MouseButton1Click:Connect(function()
if auto == false then
auto = true
else
auto = false
end
if auto == false then
while auto == true do
Player.leaderstats.Punches.Value += 1
wait(1)
end
end
end)
However, the reason this does not work is because you’re referencing the GUI in StarterGui. This is not the same as the player’s own copy. To find that you need to look into their PlayerGui located under their player object. Hopes this helps!