Uhh so I have an autoclicker script, its like a switch ui. When it's on, it turns "AutoClick" to true, and if off = to false. I don't reall know what to do to make it automatically fire an event when its set to true, and how to stop it when its set to false.
This is what I have, what do I do? (last part of a script)
switch button:
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local RS = game.ReplicatedStorage
local ClickedEvent = RS.Clicked
local frame = script.Parent.Parent
local button = script.Parent
local onPosition = UDim2.new(0, 0,0, 0)
local onColor = Color3.new(0.298039, 0.615686, 0.223529)
local offPosition = UDim2.new(0.519, 0,0, 0)
local offColor = Color3.new(0.541176, 0, 0)
local debounce = false
local waitTime = 0.5
function toggleButton()
local function toggleOn()
if debounce then return end
debounce = true
player:WaitForChild("AutoClick").Value = true
frame:SetAttribute('enabled', true)
TweenService:Create(button, TweenInfo.new(waitTime, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {Position = onPosition}):Play()
TweenService:Create(button, TweenInfo.new(waitTime, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {BackgroundColor3 = onColor}):Play()
task.wait(waitTime)
debounce = false
end
local function toggleOff()
if debounce then return end
debounce = true
player:WaitForChild("AutoClick").Value = false
frame:SetAttribute('enabled', false)
TweenService:Create(button, TweenInfo.new(waitTime, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {Position = offPosition}):Play()
TweenService:Create(button, TweenInfo.new(waitTime, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {BackgroundColor3 = offColor}):Play()
task.wait(waitTime)
debounce = false
end
if frame:GetAttribute('enabled') then toggleOff() else toggleOn() end
end
button.MouseButton1Click:Connect(toggleButton)
frame.MouseButton1Click:Connect(toggleButton)
And this is the serverscript to gain clicks:
local RS = game:GetService("ReplicatedStorage")
local ClickedEvent = RS:WaitForChild("Clicked")
ClickedEvent.OnServerEvent:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local jumpPower = leaderstats:WaitForChild("JumpPower")
jumpPower.Value = jumpPower.Value + 0.2
end)

2 comments
Yeah but it will only fire the event once, and I want to fire it every 0.2 seconds when its on, and stop firing it when the switch it turned to off.
I updated my post and gave you a link to how to repeat it