So i want the line to stop moving to the left when the tool is clicked again but it’s telling me that func1 is nil I wonder how can i stop the for loop inside of a function from running
local PitchEvents = game.ReplicatedStorage.PitchEvents
local Plr = game.Players.LocalPlayer
local Speed = 0.03
local PowerBar = script.Parent:WaitForChild("PowerBar")
local DidNotClick = false
local function MoveLineToLeft()
PowerBar.Line.Visible = true
for i = 1,0,-Speed do
PowerBar.Line.Position = UDim2.new(i,0,0,0)
wait()
if PowerBar.Line.Position.X.Scale <= 0.247 then
PowerBar.BlackCover.Size = UDim2.new(i,0,1,0)
end
end
PowerBar.Line.Position = UDim2.new(0,0,0,0)
PowerBar.BlackCover.Size = UDim2.new(0,0,1,0)
DidNotClick = true
end
local func1
PitchEvents.Click.OnClientEvent:Connect(function(clicks)
if clicks == 1 then
func1 = MoveLineToLeft()
elseif clicks == 2 then
func1:Disconnect()
end
end)
error msg
Players.sktvladimir535.PlayerGui.PitchingGui.LocalScript:46: attempt to index nil with 'Disconnect'