So I’ve made an auto clicker for my game and it works fine until I start clicking myself.
To explain this video, when I turn on my autoclicker, the stats go up just fine but when I click while it’s activated, for some reason, the value of “Heads” goes down to however many times I clicked. Can anyone tell me whats wrong with this?
Autoclicker Script - Local Script inside a ScreenGui
local activated = false
btn.Activated:Connect(function()
if activated == false then
activated = true
print("Activated")
repeat wait(0.5)
heads.Value = heads.Value + 1*headMultiplier.Value
until heads.Value == inventory.Value or activated == false
else
activated = false
end
end)
Click Script - Inside ServerScriptService activated by Remote Event
event.OnServerEvent:Connect(function(player)
h.Value += 1*m.Value -- h is the head value and m is just a multiplier
end)
Is heads a value on the server or on the client? When you updated the heads value inside the local script, you are updating the heads value on the local side, not the server. When you click yourself, you fired the event to the server, which updated the heads value on the server. Server values auto replicates to the client, so that’s why the value of “heads” went down to how many times you clicked.
Quick question. How can I send to the server that the button has been deactivated.
local activated = false
btn.Activated:Connect(function()
if activated == false then
activated = true
event:FireServer()
else
activated = false
end
end)
This is my current local script and I wanted to send the activated = false to the serverscript so it would stop the autoclicker
you can add the activated variable as an argument for the event:FireServer.
local activated = false
btn.Activated:Connect(function()
if activated == false then
activated = true
event:FireServer(activated)
else
activated = false
end
end)
and on the server side:
event.OnServerEvent:Connect(function(player,activated)
if activated then
-- activated
else
-- not activated
end
end)
clickerEvent.OnServerEvent:Connect(function(player, activated)
if activated then
repeat wait(0.5)
heads.Value = heads.Value + 1*headMultiplier.Value
if heads.Value == inventory.Value then
heads.Value = heads.Value + 0*headMultiplier.Value
end
until activated == false
end
end)
This is my current script but when I click the button again to deactivate it, it keeps going.
It doesn’t work like that. The “activated” variable passed in is a local variable of the event function.
local activated = false
clickerEvent.OnServerEvent:Connect(function(player, action)
if action == true then -- autoclicker activated
activated = true
while activated and heads.Value < inventory.Value do
heads.Value += headMultiplier.Value
wait(0.5)
end
else -- autoclicker deactivated
activated = false
end
end)
if you want your own clicks to also work, I suggest making a separate event to track your own mouse clicks.