How to disable a local function?

I was doing a script that involves a wand to have several powers however for example if I choose “power 0” it will work as I want but if I now choose “power 1” it will work as I want but the power 0 will also continue to be activated.
Each power is stored in “local functions” however I don’t know how, for example, when I choose “power 1”, the “local functions” of “power 0” have to be automatically disconnected.

How do I disconnect a “local function”?

The Code (Server Script):

local Tool = script.Parent.Parent.DebugWand
local value = Tool.SpeelId
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,mouse,id)

value.Value = id
local char = player.Character

local function GiveSpeel0()
		print("nothing")
	end
local function GiveSpeel1()
    local FireBall = game.ServerStorage.Cache.ball1:Clone()
	local Explosion = game.ServerStorage.Cache.explosion1:Clone()
	FireBall.Parent = workspace
	FireBall.Position = char.HumanoidRootPart.Position
	
	local velocity = Instance.new("BodyVelocity", FireBall)
	velocity.Velocity = CFrame.new(FireBall.Position, mouse).LookVector * 100
	
	FireBall.Touched:Connect(function(Touched)
		if Touched:IsDescendantOf(char) then return end

		Explosion.Position = FireBall.Position
		FireBall:Destroy()
		Explosion.Parent = workspace

		wait(2)
		for i = 1, 300 do
			Explosion.Fire.Size = Explosion.Fire.Size - 0.08
			Explosion.Fire.Heat = Explosion.Fire.Heat - 0.03
			wait()
		end
		Explosion:Destroy()
	end)
end
if value.Value == 0 then
	GiveSpeel0()
elseif value.Value == 1 then
	GiveSpeel1()
end
print(player.Name)
print(mouse)
print(id)

end)

You need to create a connection for your event, then call :Disconnect() when it is no longer needed.
Example here: https://developer.roblox.com/en-us/recipes/How-to-disconnect-an-event-connection

Edit: You cannot “disconnect” a function, if you don’t want it to run, simply don’t call it.

4 Likes

Although both are correct, I prefer the 1st because it explains the subject better. Thank you both for helping.

2 Likes