Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I stop firing an event?

Asked by 1 year ago

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 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

This might help. Your going need to you an if statement. Example this probably would need to be customize to work for you.

if Autoclick == true then
--put your remote event firing here

Also if autoclick isn't true it won't fire the event. This should work. Hope this helps!! (Updated) This could help Devforum

0
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. sixfirez 33 — 1y
0
I updated my post and gave you a link to how to repeat it theking66hayday 841 — 1y
Ad
Log in to vote
1
Answered by 1 year ago

Thanks! I fixed it by doing this:

player:WaitForChild("AutoClick"):GetPropertyChangedSignal("Value"):Connect(function()
    if player:WaitForChild("AutoClick").Value == true then
        print("start clicking!")
        repeat
            wait(0.2)
            ClickedEvent:FireServer(player)
        until player:WaitForChild("AutoClick").Value == false
    end
end)
0
Happy to help!! theking66hayday 841 — 1y

Answer this question