How do i end a function when i get a client event

since you haven’t sent all the variables, I can’t test this…

local connection

local function InputBegan(inp, gpe)
	local moveDirectionMagnitude = hum.MoveDirection.Magnitude
	if gpe then return end
	if inp.KeyCode == Enum.KeyCode.E then
		if debounce then return end
		local keeeeeep = rend.RenderStepped:Connect(kepmoving)
		
		debounce = true
		hum.WalkSpeed = 16
		starttter:Play()
		wait(0.3)
		charge:FireServer(damage, x, y, z)
		runner:Play()
		max:Play()
		max.Completed:Wait() 
		
		task.wait(5)
		keeeeeep:Disconnect()
		
		debounce = false
		hum.WalkSpeed = 16
		runner:Stop()
	end
end

connection = uis.InputBegan:Connect(InputBegan)
wallgit.OnClientEvent:Connect(function()
	connection:Disconnect()
	wallhitis = true
	plr.WalkSpeed = 0
	wallhit:Play()
	wait(1)
	wallhitis = false
	-- connection:Connect(InputBegan)
end)